当前位置:Gxlcms > 数据库问题 > 数据库 查询 种类

数据库 查询 种类

时间:2021-07-01 10:21:17 帮助过:84人阅读

(7)范围查询
select * from car where price>40 and price<60
select * from car where price between 40 and 60   注意:对于不同的数据库,可能会包括50,60,也可能不包括,也可能只包含1个;

(8)离散查询
select * from car where price=30 or price=40 or price=50 or price=60;
select * from car where price in(30,40,50,60)
select * from car where price not in(30,40,50,60)

(9)聚合函数(统计查询)

select count(*) as 总数 from car#取所有的数据条数

select sum(price) as 总和 from car #求价格总和
select avg(price) from car #求价格的平均值
select max(price) from car #求最大值
select min(price) from car #求最小值

注意: 取价格最高的车的全部信息: select *from car where price=(select max(price) from car);   

(10)分页查询
select * from car limit 0,10 #分页查询,跳过几条数据(0)取几条(10)
规定一个每页显示的条数:m
当前页数:n
select * from car limit (n-1)*m,m  跳过(n-1)*m条数据取m条

(11)去重查询
select distinct brand from car

(12)分组查询
查询汽车表中,每个系列下汽车的数量
select brand,count(*) from car group by brand
分组之后,只能查询该列或聚合函数

取该系列价格平均值大于40的系列代号
select brand from car group by brand having avg(price)>40

取该系列油耗最大值大于8的系列代号
select brand from car group by brand having max(oil)>8

特别注意:分组与去重的差别:表面上可能一样, 但是分组每一行都代表一个数组,一般会显示本组的第一个;

 

数据库 查询 种类

标签:条件查询   汽车   范围查询   and   group   esc   between   creat   百分号   

人气教程排行