MySQL之聚合查詢


  • 將現有的多行數據進行統計,只能看到結果
  • count(): 計算總行數,括號中寫星與列名,結果是相同的*
  • 查詢學生總數
select count(*) from students;
  • max(列): 表示此列的最大值
  • 查詢女生編號的最大值
select max(id) from students where gender=0;
  • min(列): 表示此列的最小值
  • 查詢 未刪除的學生最小編號
select min(id) from students where isDelete=0;
  • 子查詢
  • 查詢 未刪除的學生最小編號 的信息
select * from students where id=(select min(id) from students where isDelete=0);
  • sum(列): 求此列的和
  • 查詢 男生編號 的和
select * from students where gender=1;
  • avg(列):求此列的平均值
  • 查詢 未刪除的女生編號的平均值
select avg(id) from students where gender=0 and isDelete=0;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章