Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have 2 table name customer_master which have below:
cust_id cust_name cust_category
1 abc A
2 xyz B
3 qwe C

in this table i divided customer in 3 category ("A,B,C")......
i want that total customer and customer in each category like below

Exmple data from above:
totalcuatomer A B C
3 1 1 1


how can i do ?

i try this:

select cust_id,count(cust_category) from customer group by cust_category
Posted

Try this with PIVOT

VB
SELECT SUM(A+B+C) AS total, SUM(A) AS A,SUM(B) AS B,SUM(C) AS C FROM
(
    SELECT * FROM customer
) ss PIVOT
(
    COUNT(cust_id) FOR cust_category in(A,B,C)
) as pvt
 
Share this answer
 
Hello ,

Try this query .


SQL
select
(select count(*) from customer )as TotalCustomer ,
(select COUNT(*) from customer where cus_category='A')as A ,
(select COUNT(*)  from customer where cus_category='B')as B  ,
(select COUNT(*) from customer where cus_category='C') as C


thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900