聚合函數 max() 最大值 min() 最小值 avg() 平均值 sum() 求和 count() 符合條件數據的數目 聚合函數不能嵌套使用 顯示表中符合條件的信息數目,不考慮某欄位出現null值 轉換編碼 去重覆值 = 只有確定了一個值才能用 多條值用in ...
聚合函數
max() 最大值
min() 最小值
avg() 平均值
sum() 求和
count() 符合條件數據的數目
聚合函數不能嵌套使用
# 在統計時欄位內沒有滿足條件的數值只有count返回數值0或者其他,而其餘四個聚合函數返回null;
# 對於聚合函數的參數,很多時候使用欄位名來表示,那麼這個時候,該欄位內的null值不參與統計
count(*)
顯示表中符合條件的信息數目,不考慮某欄位出現null值
select count(cID),avg(elScore) from elogs;
select count(elNo),avg(elScore) from elogs;
select count(1),avg(elScore) from elogs;
select count(*),avg(elScore) from elogs;
轉換編碼
# 中文排序想要通過拼英排序的話需要轉換編碼
convert (tName using gbk)
去重覆值
# distinct 後面如果有多個欄位,則是針對這些欄位值組合後的去重
select distinct sID from Elogs;
# 先去重,再統計
select count(distinct cID) from Elogs;
= 只有確定了一個值才能用 多條值用in