我有一个如下表:
SoftwareName Count Country Project 15 Canada Visio 12 Canada Project 10 USA Visio 5 USA
如何查询它给我一个总结,如...
SoftwareName Canada USA Total Project 15 10 25 Visio 12 5 17
怎么做T-SQL?
SELECT SoftwareName, SUM( CASE Country WHEN 'Canada' THEN [Count] ELSE 0 END ) AS Canada, SUM( CASE Country WHEN 'USA' THEN [Count] ELSE 0 END ) AS USA, SUM( [Count] ) AS Total FROM [Table] GROUP BY SoftwareName;