Mysql 'case' with multiple WHEN values

I have a query that should do a column count, where 2 other columns are true. I need to read "DealerName" when "DealerName", for example, "% MINI%" and "DealerContact_Y" = 1

But I'm not sure about the syntax. This request causes an error

SELECT DealerName, count(DealerShipId) as dealersContacted, CASE WHEN DealerName LIKE "%MINI%", WHEN DealerContact_Y = 1 THEN Count(DealerContact_Y) END as Mini_contacted_yes, Campaign, DealerId FROM tblsummaryResults 

Is there a way to make mutiple WHENS in a case statement?

+4
source share
2 answers

You will write it like this using DealerName LIKE '%MINI%' AND DealerContact_Y = 1 :

 SELECT DealerName, count(DealerShipId) as dealersContacted, count(CASE WHEN DealerName LIKE '%MINI%' AND DealerContact_Y = 1 THEN DealerContact_Y END) as Mini_contacted_yes, Campaign, DealerId FROM tblsummaryResults 
+4
source

So do this:

 COUNT( IF(DealerName LIKE "%MINI%" AND DealerContact_Y = 1, DealerContact_Y, NULL) ) AS Mini_contacted_yes 
+1
source

All Articles