ITeye博客

sql查询

sinxadmin · 2011-04-12 13:52 · Oracle · 数据库 · Markdown

1.查询重复数据

查询test表中A列值为100的时候B列重复的数据,例如:

A        B       C        D

100    hz

100    lh

100    hz

那么显示B为hz的行

select * from test where A= 100 and  B in (

select B from test where A= 100 group by A,B  having count(*) > 1 )

2.分组去重复统计查询

统计test表中每天的用户访问量,例如:

A                      B      C        D

2011-01-01      a

2011-01-01      b

2011-01-01      a

2011-01-02      b

2011-01-02      b

显示结果为

A                      B

2011-01-01      2

2011-01-02      2

 

select A ,count(*) from  (select  * from test   group by A,B) test group by A

先通过select  * from test   group by A,B去重复再进行分组计算

 

或者可以使用select count(dinstinct B) from test group by A

 

3.mysql设置列唯一性

create unique index column_index on  table(column)

 

4.mysql insert忽略错误

insert ignore into tb(...) value(...)

 

5.mysql查看表创建语句

mysql> show create table  tb

 

6.mysql查看列的详细信息

mysql> show full columns from tb

 

7.mysql查看字符集

mysql> show variables like '%char%'

 

8.mysql设置连接字符集

set names gb2312;

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。