我有一张桌子,这张桌子有三列 像这样
--------------
|Name|ID |Num|
--------------
|A |001|1 |
|A |001|2 |
|A |001|3 |
--------------
我想要显示NAME ID和Num的总数 像anwser
NAME ID NumTOTAL
A 001 6
答案 0 :(得分:8)
您可以使用SUM()
:
SELECT Name, ID, SUM(Num) AS NumTOTAL
FROM yourTable
GROUP BY Name, ID
答案 1 :(得分:1)
使用sql
的sum()函数后很容易select name,id sum(num) as [Total Num] from tableName Group by name,id