gpt4 book ai didi

sql - 汇总汇总数据

转载 作者:行者123 更新时间:2023-12-03 01:51:06 25 4
gpt4 key购买 nike

我有一个如下表:

SoftwareName    Count    CountryProject         15       CanadaVisio           12       CanadaProject         10       USAVisio           5        USA

我如何查询它来给我一个总结,比如......

SoftwareName    Canada    USA    TotalProject         15        10     25Visio           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;

关于sql - 汇总汇总数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/248990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com