[Mysql 查詢語句]——集合函式

Jelly_lyj發表於2017-03-18

count() 統計記錄條數

select count(*) from student;
+----------+
| count(*) |
+----------+
|        4 |
+----------+

 

sum()求欄位總和

(1) sum函式只能計算數值型別的欄位:int、float、double、decimal等
(2) 不能用於計算字元型別欄位,結果都為0

select sum(age) from student;
+----------+
| sum(age) |
+----------+
|      104 |
+----------+

 

avg()求欄位平均數

select avg(age) from student;
+----------+
| avg(age) |
+----------+
|  26.0000 |
+----------+

 

max()求欄位最大值

select max(num) from student;
+----------+
| max(num) |
+----------+
|        4 |
+----------+

 

min()求欄位最小值

select min(num) from student;
+----------+
| min(num) |
+----------+
|        1 |
+----------+

 

相關文章