码迷,mamicode.com
首页 > 数据库 > 详细

MySQL基本操作-SQL查询语句

时间:2015-10-13 13:45:13      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

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条记录

     

MySQL基本操作-SQL查询语句

标签:

原文地址:http://www.cnblogs.com/mingshsu/p/4874205.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!