0

My MySql db table structure is:

id | status
1  |  Open
2  |  Open
3  |  Closed
4  |  Open
5  |  Closed

and i want to count total number of Open and Closed rows.

Status | Total
Open   |   3
Closed |   2

I used

SELECT count(distinct status) as Total FROM my_tbl

but it returns

Total
  2

1 Answer 1

5

SELECT status,
COUNT(id) AS `total`
FROM your_table
GROUP BY status
ORDER BY total DESC

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.