mysql views my query output i need different manner

This is my query

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  

Please help me This is my query output

Email   Sms     Survey    
21     1       4

i need output like this

 name    value  
 Email   21  
 Sms     1   
 Survey  4

Please tell me how to get like above optput

Asked By: mohan
||

Answer #1:

TRY

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

Answered By: diEcho
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .



# More Articles