mysql查看我的查询输出我需要不同的方式

时间:2011-03-24 06:31:57

标签: mysql

这是我的查询

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

请告诉我如何获得上述

1 个答案:

答案 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

Reference