coolboy
coolboy

Reputation: 113

Combine multiple MySql queries into a single query

i have table name users.

id   name date       cdate           c  a   b
1     rz  42121221  42121221         0  1   0
2     an  12122111  42121221         0  0   1
3     cb  22121221  42121221         1  1   1   
4     ss  3321221   42121221         1  0   0

i have two select the values between two dates,and then i have to find the count using this statement.

 SELECT COALESCE(SUM(IF(c=1 AND a=0 AND b=1  ,  1, 0)),0) AS ACTIVE WHERE DATE BETWEEN 'DATE 1' AND 'DATE 2',COALESCE(SUM(IF(c=0 AND a=0 AND b=1  ,  1, 0)),0) AS INC WHERE cdate BETWEEN 'DATE 1' AND 'DATE 2' FROM users

this query is not working

Upvotes: 0

Views: 118

Answers (1)

hkutluay
hkutluay

Reputation: 6944

Use like

select COALESCE(SUM(IF(c=1 AND a=0 AND b=1  ,  1, 0)),0) AS ACTIVE from users where date between 'date1' and date '2'

Upvotes: 1

Related Questions