我有一個表:Sum函數2008
PropertyID Amount
--------------------------
1 40
1 20
1 10
2 10
2 90
我想實現:
PropertyId Amount Total_Amount
---------------------------------------
1 40 70
1 20 70
1 10 70
2 10 100
2 90 100
使用下面的查詢:
SELECT
PropertyID,
SUM(Amount),
SUM(TotalAmount)
FROM
yourTable
WHERE
EndDate IS NULL
GROUP BY
PropertyID
輸出:
PropertyId Amount TotalAmount
-------------------------------------
1 70 70
2 100 100
讓我知道我能得到我想要的輸出...
什麼版本的SQL Server? –