0

我有表名用户。

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

此查询不起作用

4

1 回答 1

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'
于 2012-06-08T11:35:50.587 回答