I have a table with two columns:
column A column B 1 2 1 2 2 1
I want to return the total number of them = 3 only two = 3
The best I can think of is two queries:
SELECT sum(CASE WHEN columnA =1 THEN 1 ELSE 0 END ) + sum(CASE WHEN columnB =1 THEN 1 ELSE 0 END ) SELECT sum(CASE WHEN columnA =2 THEN 1 ELSE 0 END ) + sum(CASE WHEN columnB =2 THEN 1 ELSE 0 END )
Can this be done in a single request? thanks
php mysql
bsandrabr
source share