数据库(5)聚合、分组、排序、分页

聚合

count(*) 统计总行数

select count(*) from table where id_delete=0;

max(列) 求该列的最大值

select max(id) from table where gender=0;

min(列 )求该列的最小值

select min(id) from table where gender=1;

sum(列) 求列的和

同上

avg(列) 求列的平均值

 同上

分组

关键字: group by

eg: select count(*) from table broup by gender;

分组后的数据筛选:

关键字:having

eg: select gender,count(*) as num from table broup by gender having num > 2;

where VS having

1) where是对from后面指定的表进行数据筛选,属于对原始数据的筛选;
2)having是对group by分组后的结果进行筛选。

排序

关键字:order by

eg:select * from table order by row1 asc|desc, row2 asc|desc...;

默认升序

asc 为升序

desc 为降序

分页

应用场景:数据量过大,在一页中查看数据较麻烦

语法:select * from table limit start, count;

从start开始,获取count条数据

start索引从0开始

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值