标签:
1.查询数据
select 属性列表
from 表名和视图列表
[where 条件表达式1]
[group by 属性名1 [having 条件表达式2] [with rollup最后加一条记录是上面记录的总和]] //按照属性名1指定的字段分组,有having则要满足条件表达式2
[order by 属性名2 [asc|desc]]
where查询条件:
比较 =、<、<=、 >、>=、!=、<>、!>、!<
指定范围 between and、not between and
指定集合 in、not in
匹配字符 like、not like <%:代表任意长度字符串,_:代表单个字符>
是否为空值 is null、is not null
eg:select * from test0 where id in (1001,1004,1005);
select * from test0 where id between 1002 and 1005;
select * from test0 where id < 1004 and name like ‘h_h_‘; //两个条件均满足
select * from test0 where id < 1004 or name like ‘h%‘; // 满足其中一个便可
select distinct name from test0; //查询结果不重复
select id,group_concat(name) from test0 group by name;//将name分组中指定字段值都显示出来
select name,count(name) from test0 group by name;//将name分组的每一组记录数统计出来
select name,count(name) from test0 group by name having count(name) > 1; //显示记录数大于1的
having表达式是作用于分组后的记录,而where作用于表或者视图。
select name,count(name) from test0 group by name with rollup;
select * from test0 limit 3; //只显示3条记录
select * from test0 limit 1,3; //从第2条记录起显示3条记录
标签:
原文地址:http://www.cnblogs.com/mingshsu/p/4874205.html