请帮忙。假设我有下表
我想要的是将每种货币的金额和每种货币的数量相加并将它们放入新的列中。 select语句应该如何?谢谢
答案 0 :(得分:1)
SELECT
Amount
,Currency
,(SELECT SUM(Amount) FROM TableName WHERE Currency = 'USD' GroupBy Currency) as USD_SUM
,(SELECT COUNT(*) FROM TableName WHERE Currency = 'USD) as USD_Count
..... Repeat for other currencies
FROM TableName
不是最好的方法,但它解决了问题。
答案 1 :(得分:0)
目前还不是很清楚你真正想要的,所以我只想假设:
SELECT Curency, sum(Amount) as SumAmount, count(Amount) as CountAmount
From table
Group by Curency
但请下次尝试先自己解决。