将多个MySql查询合并到一个查询中

时间:2012-06-08 11:28:07

标签: php mysql sql

我有表名用户。

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

我有两个选择两个日期之间的值,然后我必须使用此语句找到计数。

 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

此查询无效

1 个答案:

答案 0 :(得分:1)

使用

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'