Mysql 第六天 使用聚合函數查詢

5.1     count()函數函數

SELECT COUNT(*) FROM t_grade;spa



SELECT COUNT(*) AS total FROM t_grade;im


SELECT stuName,COUNT(*) FROM t_grade GROUP BY stuName;img

5.2     sum函數co

SELECT stuName,SUM(score) FROM t_grade WHERE stuName = '張三'

SELECT stuName,SUM(score) FROM t_grade GROUP BY stuName;

5.3     avg函數


SELECT stuName,AVG(score) FROM t_grade WHERE stuName = '張三'

SELECT stuName,AVG(score) FROM t_grade GROUP BY stuName;

5.4     max函數


SELECT stuName,MAX(score) FROM t_grade WHERE stuName = '張三'



SELECT stuName,MAX(score) FROM t_grade GROUP BY stuname;

5.5     min函數


SELECT stuName,MIN(score) FROM t_grade WHERE stuName = '張三'

SELECT stuName,MIN(score) FROM t_grade GROUP BY stuname;

相關文章
相關標籤/搜索