1

I have a table like this-

Table

I want to run a query so that I can have a output like it-

enter image description here

I don't have a clear idea how to do it. So, what I have done is-

SELECT
        Count(* where status="Active") as count_active
        Count(* where status="Inctive") as count_inactive
        Count(* where status="Biase") as count_biase
    FROM `subscribers`

And getting error, can anyone please help?

2 Answers 2

3

Can achieve this with a Case expression.

Query

select 
count(case when status = 'Active' then 1 else null end) as Active_Count,
count(case when status = 'Inactive' then 1 else null end) as Inctive_Count,
count(case when status = 'Biase' then 1 else null end) as Biase_Count
from tbl_name;

SQL Fiddle

Sign up to request clarification or add additional context in comments.

Comments

0

This is the way to put it in a single register:

SELECT 
(SELECT count(id) FROM new_table where status = 'Active') as Active_Count,
(SELECT count(id) FROM new_table where status = 'Inactive') as Inctive_Count,
(SELECT count(id) FROM new_table where status = 'Biase') as Biase_Count;

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.