数据库聚合
https://www.cnblogs.com/yzl050819/p/8284242.html 安装sqlserver
SELECT TOP /SELECT TOP PERCENT子句用于指定要返回的记录数量----------SELECT TOP 2 * FROM Customers; /SELECT TOP 50 PERCENT * FROM Customers;
百分号表示零个,一个或多个字符,下划线表示单个字符-------------------------WHERE CustomerName LIKE 'a_%_%'
字段去重:distinct
select distinct sex from t;
聚合函数sum/min/max/avg
SELECT AVG(student_age)FROM t_student;
group by分组
select sex,count(*) from t group by sex;
having过滤条件
select sex,avg(id) from t group by sex having avg(id)=4;查询平均id等于4的性别
执行顺序:where条件>group by分组>having过滤(聚合函数)>order by排序
一起使用:
select sex,sum(id) from t where id>2 group by sex having sum(id)>=12 order by sum(id)
desc;查询id大于2的id值总计大于等于12的性别分组并且按照id倒序显示