当前位置: 移动技术网 > IT编程>数据库>Mysql > mysql查询

mysql查询

2019年02月26日  | 移动技术网IT编程  | 我要评论

  select [distinct]* | 列名1,列名2,...[ as 别名]

  from 数据源 [ as 别名]

  [ where 条件表达式 ]

  [ group by 分组字段 [ having 条件表达式 ] ]

  [ order by 排序字段 [ asc | desc ] ]

  [limit [行偏移] 行数目]

  注:[] 表示可选输入项,| 表示或者。列名列表可使用 * 表示所有。

 

  一. where

   1). 比较大小:= , < , <= , > , >= , != , <> , !> , !< ,<=>

    <>等同!=,<=>用于比较null

   2). 指定范围:between ... and ... , not betweent ... and ...

   3). 匹配字符:like , not like , rlike , not rlike , regexp , not regexp ,in , not in

    like用于模糊查询,rlike用于匹配正则表达式。

    参考:

    in() :比配括号中的内容。

   select * from emp where a in(1,3,5); //查询emp表中a等于1或者3或者5的信息

   4). 是否为空:is null , is not noll

   5). 多条件查:and , or

  二. group by :分组

   group by一般搭配聚合函数使用。

  三. order by : 按字段大小进行排序,默认为升序排序。asc,升序;desc 降序。

  select * from stu order by id desc; //按id降序排序查询stu表信息

 

  四. distinct :去除重复的数据

    select distinct sname , sex , birthday from stu; //查询stu表中的sname,sex,birthday的信息,有重复的只显示一次

  五. limit :限制返回行数

   select * from stu limit 2,3; //查询stu表,从第2行开始的3行信息,即2-4行

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网