这是我的查询
Select Count(Case When campaign_pid != 0 Then 1 End) As Email,
Count(Case When sms_pid != 0 Then 1 End) As Sms,
Count(Case When survey_pid != 0 Then 1 End) As Survey
From tablename
请帮帮我 这是我的查询输出
Email Sms Survey
21 1 4
我需要这样的输出
name value
Email 21
Sms 1
Survey 4
请告诉我如何获得上述
答案 0 :(得分:0)
尝试
SELECT COUNT(Case WHEN campaign_pid != 0 THEN 1 END) AS Email FROM tablename
UNION
SELECT COUNT(Case WHEN sms_pid != 0 THEN 1 END) As Sms FROM tablename
UNION
SELECT COUNT(Case WHEN survey_pid != 0 THEN 1 END) As Survey FROM tablename