Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8042405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:34:00+00:00 2026-06-05T04:34:00+00:00

I have a table named users. id name date cdate c a b 1

  • 0

I have a table named 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 to 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 where dealer id='2'

This query is not working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:34:01+00:00Added an answer on June 5, 2026 at 4:34 am

    Here’s your query, properly formatted. You can only have one WHERE clause per SELECT statement, and the FROM clause goes after the SELECT clause and before the WHERE clause.

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

    I copied your date comparisons into the IF statements.

    Also, I removed the COALESCE clause because it was redundant in this case. SUM always returns a value.

    I put the columns together, separated by a comma, after the SELECT clause.

    You may wish to remove the WHERE clause now, depending on what you’re trying to do.

    I’m also suspicious of cdate BETWEEN 'DATE 1' AND 'DATE 2'. If cdate is a DATETIME column, you’ll want to put in properly formatted dates in the constants. If DATE 1 and DATE 2 are column names, then you’ll need back ticks, not single quotes, like this:

    cdate BETWEEN `DATE 1` AND `DATE 2`
    

    You should consider reading the documentation on the SELECT syntax.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have table name users. id name date cdate c a b 1 rz
I have Two tables. 1.Users table (Username , Name) 2.Picture table( ID , Username
I have i table users (id,name) and operations (id,date,id_user,id_target_user) if i didn't have the
I have a table with users: name | country | .. | UK |
I have a picture table which consists for users pictures Table Name:picture Columns: picture_id
Say I have a table called Users, which contains your typical information: Id, Name,
i have a table named IMAGES in which there is attribute name img_ID which
I have table with data about tasks like Id, Name, Date, WorkerId, VehicleId (and
I have a table of users which has a date field for their birthday:
I have this users table with: id : int (255) name: char (100) last_comment_target:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.