3.给列指定名称
select code as ‘代号‘,name as ‘姓名‘ from info
4.条件查询
select * from info where code=‘p001‘
select * from info where code=‘p001‘ or nation=‘n001‘ 或关系
select * from info where code=‘p001‘ or nation=‘n001‘ 并且关系
5.模糊查询(经常用到)
select * from car where name like ‘%奥迪%‘ 前面后面有n个字符
select * from car where name like ‘_奥迪%‘ 前面出现一个字符
6.排序查询
默认为主键排序
select * from car order by price 以价格进行排序,默认按升序排序
select * from car order by price desc 按降序排列
select * from car order by price asc 按升序排列
select * from car order by price asc,oil desc 按两列排序
7.去重查询
select brand from car 查询brand列
select distinct brand from car 去重查询
8.分页查询(取几条数据)
select * from car limit 5,5 跳过5条,取5条 (当前页-1)*5
9.统计查询(聚合函数)
数据条数
select count(*) from car 有多少数据
select count(code) from car 只看主键列,可以提高查询效率
取最大值
select max(price) from car 取price列的最大值
最小值
select min(price) from car 取price列的最小值
取平均值
select avg(price) from car 取price的平均值
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)
select * from car where price not in(10,20,30)