如何根据另一列中的某组条件在列中添加不同的值? 与使用Sumif
在excel上完成的相同答案 0 :(得分:1)
Select SalesAgent
,JanSales = sum(case when SalesMonth=1 then Sales else 0 end)
,FebSales = sum(case when SalesMonth=2 then Sales else 0 end)
... {march - november}
,DecSales = sum(case when SalesMonth=12 then Sales else 0 end)
,Total = sum(Sales)
From SalesData
Group By SalesAgent
Order By SalesAgent
答案 1 :(得分:0)
要为符合特定条件的行汇总列的所有值:
SELECT Sum(value1) FROM Table WHERE value2=something