注册 登录
编程论坛 SQL Server论坛

SQL Server 2014怎么可以使多个结果变成横排,并且第一列一一对应上

lingerfanny 发布于 2023-05-05 18:35, 581 次点击
SQL Server 2014 Management Studio

怎么样可以让下面几个数据变成横排,并且对应相应的地市?
原使用的公式如下:
elect ABC0501."地市",count("5G省内流量(T)"+"5G省外流量(T)") AS '大于10T卡数量' from ABC0501 where "5G省内流量(T)"+"5G省外流量(T)">10000 group by "地市"
select ABC0501."地市",count("5G省内流量(T)"+"5G省外流量(T)") AS '大于20T卡数量' from ABC0501 where "5G省内流量(T)"+"5G省外流量(T)">20000 group by "地市"
select ABC0501."地市",count("5G省内流量(T)"+"5G省外流量(T)") AS '大于30T卡数量' from ABC0501 where "5G省内流量(T)"+"5G省外流量(T)">30000 group by "地市"



只有本站会员才能查看附件,请 登录
2 回复
#2
lingerfanny2023-05-16 10:44
哪位大神可以帮帮忙哦,我初学者不会写
#3
阳光上的桥2023-05-18 16:06
SELECT 地市
,SUM(CASE WHEN "5G省内流量(T)"+"5G省外流量(T)">10000 THEN 1 ELSE 0 END) AS 大于10T卡数量
,SUM(CASE WHEN "5G省内流量(T)"+"5G省外流量(T)">20000 THEN 1 ELSE 0 END) AS 大于20T卡数量
,SUM(CASE WHEN "5G省内流量(T)"+"5G省外流量(T)">30000 THEN 1 ELSE 0 END) AS 大于30T卡数量
FROM ABC0501
GROUP BY 地市



[此贴子已经被作者于2023-5-18 16:08编辑过]

1