SQL Server 查
注:where语句是条件,后面加and或者or
时间日期:比时间需要时间加引号
模糊查询:where语句后面加like '%包含此关键字%'或者'以此关键字开头%'或者'%结尾'
排序查询:列名 order by根据指定列进行排序,asc升序但是默认增序,desc降序
去重查询:distinct 用法单一
聚合函数:平均,计数,最大,最小等等 配合 group by(根据列名分组) group by后面加条件的方法是having
子查询:where后面加in('表格内数据','表格内数据') 或者 between后面写条件
--聚合函数
select brand,COUNT(*) from car group by brand
select brand,AVG(oil) from car group by brand
select brand,max(oil) from car group by brand
select brand,min(oil) from car group by brand
select brand,sum(oil) from car group by brand
select brand,(max(oil)+min(oil))/2 from car group by brand
--group by brand having oil > AVG(oil)
--子查询
use Test
select * from car where brand in('b001','b002','b003')
select * from car where brand in(
select brand from car where name like '%奥迪%')
select * from car where price between 30 and 50