my sql sum the count values
Select Count(Case When an_user_plan.campaign_pid != 0 Then 1 End) As Email,
Count(Case When an_user_plan.sms_pid != 0 Then 1 End) As Sms,
Count(Case When an_user_plan.survey_pid != 0 Then 1 End) As Survey,
sum(Email,Sms,Survey)as total
From an_user_plan
This sum(Email,Sms,Survey)as total
开发者_如何学Go have error how to sum the three values
I want total as addition of three count vlaues
how to do Please help me
SELECT SUM(campaign_pid != 0 +
sms_pid != 0 +
survey_pid != 0) AS total, ...
Try this:
Select Count(Case When an_user_plan.campaign_pid != 0 Then 1 End) +
Count(Case When an_user_plan.sms_pid != 0 Then 1 End) +
Count(Case When an_user_plan.survey_pid != 0 Then 1 End) as total
From an_user_plan
While you have no GROUP BY clause, you could use variables -
SELECT @c1:=Count(...), @c2:=Count(...), @c1 + @c2 FROM table
Otherwise you can use a subquery -
SELECT c1, c2, c1 + c2 FROM (
SELECT Count(...) c1, Count(...) c2 FROM table) t
精彩评论