使用count(*)做统计,不受 NULL影响
命令:select count(*) from t1;
使用count(name),不统计统计非NULL
命令:select count(name) from t1;
使用count(distinct id) ,去重id 的数量。
命令:select count(distinct id) from t1;
sun(score)统计分数的和
命令:select sun(score) from t1;
统计score小于70分的和
命令:select sun(score) from t1 where score<70;
统计score小于70分的和,没有结果返回为空。
命令:select sum(score) from t1 where score < 30;
avg()统计匀称分
命令:select avg(score) from t1;
8.max 统计最高分
命令:select max(score) from t1;
min()找出高于或便是60的最低分
select min(score) from t1 where score >=60;
6. 分组聚合 GROUP BY
6.1 界说
GROUP BY 子句在 SQL 中用于将数据按照一个或多个列进行分组。它的重要作用是将具有相同值的行组合在一起,以便可以对每个组实行聚合函数(如 SUM、COUNT、AVG 等)或其他操作。GROUP BY 通常与聚合函数一起使用,以生成汇总陈诉。
语法:
SELECT column1, column2, aggregate_function(column3)
FROM table_name
WHERE condition
GROUP BY column1, column2; 说明: