码迷,mamicode.com
首页 > 其他好文 > 详细

简单查询

时间:2018-01-02 11:25:12      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:like   count   class   条件查询   group by   笛卡尔   根据   bsp   出现   

简单查询
1查询所有数据
selete * from info
2查询指定列
select code,name from info
3给列指定名称
select code as ‘代号‘,name as ‘姓名‘ from info
4条件查询
select * from info where code=‘p001‘
5模糊查询:根据关键字查询
select * from car where name like ‘_奥迪_‘ %百分号奥迪前面可以有N个字符,可以后面有N个字符;_下滑线只能出现一个字符,
6排序查询
select * from car order by price desc,oil desc
代表以价格进行排序,price后面不加,默认升序排列,降序使用desc;price是第一优先级排序,如果价格相等则oil排序
7去重查询
select distinct brand from car
8分页查询
select * from car limit 5,5
跳过几条,取几条
9统计查询或聚合函数
select count(*) from car查询出多少条数据
取最大值
select max(price) from car
取最小值
select min(price) from car
取平均值
select avg(price) from car
分组查询
select brand,count(*) from car group by brand
select brand from car group by brand having count(*)>=3
范围查询
select * from car where price>=40 and price<=60
select * from car where price between 40 and 60
离散查询
select * from car where price in(10,20,30,40)在里面出现
select * from car where price not in(10,20,30,40)不在里面出现
联合查询
union
连接查询
形成笛卡尔积

 

简单查询

标签:like   count   class   条件查询   group by   笛卡尔   根据   bsp   出现   

原文地址:https://www.cnblogs.com/forqiwen/p/8175607.html

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