美文网首页
数据库操作--聚合分组

数据库操作--聚合分组

作者: 生命有一种执着 | 来源:发表于2020-04-21 16:10 被阅读0次

1、聚合函数

统计:select count(id) from tb;

最大值:select max(id) from tb;

最小值:select min(id) from tb;

平均值:select avg(id) from tb;

求和:select sum(id) from tb;

列出字段全部值:select group_concat(id) from tb;

2、分组查询

select id from tb2 group by id;(自动去重排序)

3、聚合筛选

select id from tb group by id having id < 4;

select id from tb1 where id >1 group by id having id < 5;(先进行where筛选,在进行having筛选)

4、子查询(嵌套查询)

select * from tb where id < (select avg(id) from tb);

相关文章

网友评论

      本文标题:数据库操作--聚合分组

      本文链接:https://www.haomeiwen.com/subject/aaguihtx.html