อยากให้เป็นแบบนี้
//customer_type_id ที่มีการแสดง status ใช้งานกี่คน / และไม่ใช้งานกี่คน
อันนี้ที่ทำไว้ครับ
Code (SQL)
select Customer_Type_id ,count(Status) as status1 from ms_Customer
where ms_Customer.Status = 1 GROUP BY Customer_Type_id
select Customer_Type_id ,count(Status) as status2 from ms_Customer
where ms_Customer.Status = 2 GROUP BY Customer_Type_id
Tag : PHP, MySQL, Ms SQL Server 2008, Ms SQL Server 2012
select
Customer_Type_id ,
count(Customer_id) as all_Customer,
sum(Status=1) as status1,
sum(Status=2) as status2
from ms_Customer
GROUP BY Customer_Type_id
select Customer_Type_id
,count(case when ms_Customer.Status = 1 then 1 else null end) as status1
,count(case when ms_Customer.Status = 2 then 2 else null end) as status2
from ms_Customer
GROUP BY Customer_Type_id
select A,
SUM(case when b=1 then 1 else 0 end) as b1,
SUM(case when b=2 then 1 else 0 end) as b2
from (
select '1' as A, 1 as b union all
select '1' , 2 union all
select '2' , 2 union all
select '2' , 1 union all
select '1' , 2 union all
select '1' , 2 union all
select '2' , 2 union all
select '2' , 1 union all
select '2' , 2
) as tmp group by A