W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
SUM函數(shù)用于找出表中記錄在某字段處的總和。
要理解 SUM 函數(shù),請考慮 employee_tbl 表,表中記錄如下所示:
SQL> SELECT * FROM employee_tbl;
+------+------+------------+--------------------+
| id | name | work_date | daily_typing_pages |
+------+------+------------+--------------------+
| 1 | John | 2007-01-24 | 250 |
| 2 | Ram | 2007-05-27 | 220 |
| 3 | Jack | 2007-05-06 | 170 |
| 3 | Jack | 2007-04-06 | 100 |
| 4 | Jill | 2007-04-06 | 220 |
| 5 | Zara | 2007-06-06 | 300 |
| 5 | Zara | 2007-02-06 | 350 |
+------+------+------------+--------------------+
7 rows in set (0.00 sec)
現(xiàn)在,假設(shè)你想要獲取 daily_typing_pages 的總和,那么你可以用如下命令來達(dá)到目的:
SQL> SELECT SUM(daily_typing_pages)
-> FROM employee_tbl;
+-------------------------+
| SUM(daily_typing_pages) |
+-------------------------+
| 1610 |
+-------------------------+
1 row in set (0.00 sec)
你還可以使用 GROUP BY 子句來得出不同記錄分組的總和。下面的例子將會(huì)計(jì)算得出每個(gè)人的總和,,你將能夠得到每個(gè)人每天打的總頁數(shù)。
SQL> SELECT name, SUM(daily_typing_pages)
-> FROM employee_tbl GROUP BY name;
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: