0

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

3
  • What's your expected outcome? Where's the second query? Commented Jun 8, 2012 at 11:30
  • Why do you want to do it in a single statement? What benefit will this give you? Commented Jun 8, 2012 at 11:30
  • first i want to get the values between two dates then i have to use this query SELECT COALESCE(SUM(IF(c=1 AND a=0 AND b=1 , 1, 0)),0) AS ACTIVE Commented Jun 8, 2012 at 11:33

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.