数据库聚合函数

聚合函数
count 用来统计一共有多少条记录
select count(id) from students;
sum 用来计算和
select sum(score) from students;
max 用来求最大值
select max(score) from students;
min 用来求最小值
select min(score) from students;
avg 用来求平均值
select avg(score) from students;
这里还可以组合使用   as  起别名:
select count(id) as 总条数,sum(score) as 总和,max(score) as 最大值, min(score) as 最小值, avg(score) as 平均值 from students;
order by 对查询结果进行排序,asc 升序,desc.
可以多字段查询,在前边的优先级高,
一个小例子,成绩降序,成绩一样,年龄升序
select score,age from students order by score desc,age asc;
limit 指定查询记录多少条
select score,age from students order by score desc,age asc limit 3;
也可以这样使用,从第几条开始。这就是从第二条开始
select score,age from students order by score desc,age asc limit 2,3;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值