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

  • Home
  • SEARCH
  • 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 8888379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:01:02+00:00 2026-06-14T22:01:02+00:00

My query select state,count(*) from crm_lead group by state; which return state count done

  • 0

My query

select state,count(*) from crm_lead group by state;

which return

state   count
done    794
open    560
pending 3
draft   8
cancel  1

but sometime when I have no ‘cancel’ task in my table

state   count
done    794
open    560
pending 4
draft   8

I would like to include count = 0 in the result, what is the best query ?

  • 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-14T22:01:04+00:00Added an answer on June 14, 2026 at 10:01 pm
    SELECT  a.STATE , 
            COALESCE(b.count, 0) AS Count
    FROM 
        (
            SELECT 'done' AS STATE
            UNION
            SELECT 'open' AS STATE
            UNION
            SELECT 'pending' AS STATE
            UNION
            SELECT 'draft' AS STATE
            UNION
            SELECT 'cancel' AS STATE
        ) a LEFT JOIN 
        (
            SELECT  STATE , 
                    count(*) AS count
            FROM    crm_lead
            GROUP BY STATE
        ) b ON a.STATE = b.STATE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why query: SELECT id, MAX(probe_time) AS Expr1 FROM app_states GROUP BY logon_id and SELECT
When I run query number 1: SELECT id, name, COUNT(name) AS count FROM markers
I have a query like this: SELECT t1.id, (SELECT COUNT(t2.id) FROM t2 WHERE t2.id
I have a query like this: SELECT state AS ls,count(*) AS total, max(sales) AS
Here is my query: SELECT COUNT(*) FROM Similarities WHERE T1Similarity = 0 OR T2Similarity
I have following SQL query: SELECT Count(*) AS CountOfRecs FROM tblAccount INNER JOIN tblAccountOwner
SELECT COUNT(*) AS count, state, DATE_FORMAT( '%m/%d', registered ) AS date_formatted FROM users WHERE
I have the following query: SELECT COUNT(employees.id) AS emp_count FROM `orders` INNER JOIN `companies`
i have this Query : SELECT a.*, a.id AS id_player, (SELECT COUNT(id) FROM `vd7qw_footsal_goals`
I'm looking for help using sum() in my SQL query: SELECT links.id, count(DISTINCT stats.id)

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.