简单查询
1.最简单查询(查所有数据)
select * from info
2.查询指定列
select code,name from info
3.修改结果集的列名
select code as '代号',name as '姓名' from info
4.条件查询
select * from info where code='p003'
5.多条件查询
查询info表中code为p003或者nation为n001的所有数据
select * from info where code='p003' or nation='n001'
查询info表中code为p004并且nation为n001的数据
select * from info where code='p004' and nation='n001'
6.范围查询
Select * from car where price>=40 or price<=60
Select * from car where price between 40 and 60
7.离散查询
Select * from car where price=10 or price=20 or price=30 or price=40 or price=50 or price=60
Select * from car where price in(10,20,30,40,50,60)
8.模糊查询
Select * from car where name like ‘%奥迪%’
Select * from car where name like ‘_马%’ 任意一个字符
9.排序查询
Select * from car order by price asc asc升序排列
Select * from car order by brand price desc desc按价格降序排列
10.去重查询
Select distinct brand from car
11.分页查询
一页显示十条 当前是第三页
Select * from chinastates limite 20,10
12.聚合函数(统计函数)
Select count(arecode) from chinastates #查询数据总条数
Select sum(price)from car #求和
Select avg(price)from car #求平均
Select max(price)from car #求最大值
Select min(price)from car #求最小值
13.分组查询
查询汽车表中每个系列下有多少个汽车
select brand count(*) from car group by brand