查询
简单查询:
1.查询所有数据
select * from info
2.查询指定列
select code,name from info
3.给列指定名称
select code as '代号',name as '姓名' from info
4.条件查询
select * from info where code='p001'
select * from info where code='p001' and nation='n001'
5.模糊查询
select * from car where name like '%奥迪%'
6.排序查询
select * from car order by price asc,oil desc
7.去重查询
select distinct brand from car
8.分页查询
select * from car limit 5,5
9.统计查询(聚合函数)
数据条数
select count(code) from car
取最大值
select max(price) from car
取最小值
select min(price) from car
取平均值
select avg(price) from car
10.分组查询
select brand,count(*) from car group by brand
select brand from car group by brand having count(*)>=3
11.范围查询
select * from car where price>=40 and price<=60
select * from car where price between 40 and 60
12.离散查询
select * from car where price in(10,20,30,40,50,60)
select * from car where price not in(10,20,30,40,50,60)