我有一張名爲tblEmployee
的表格。我想總結價值並按UserId
分組。如何在SQL Server中使用Group by對多列進行求和?
tblEmployee:
+--------+----------+-------+
| UserId | UserName | Value |
+--------+----------+-------+
| 1 | A | 100 |
| 1 | B | 200 |
| 1 | C | 300 |
| 2 | D | 100 |
| 3 | E | 200 |
| 3 | F | 300 |
+--------+----------+-------+
我想總結基於userid
並顯示像下面輸出的值。
輸出:
+--------+----------+-------+---------+
| UserId | UserName | Value | Result |
+--------+----------+-------+---------+
| 1 | A | 100 | |
| 1 | B | 200 | 600 |
| 1 | C | 300 | |
| 2 | D | 100 | 100 |
| 3 | E | 200 | |
| 3 | F | 300 | 500 |
+--------+----------+-------+---------+
怎麼辦呢?
大和很多感謝的話。 – dhamo