I need help How can I merge the column into a single column, here is my code, is this method is correct. I want to get the count of the selected row in the table for the columns.
SELECT CAT_MGR, SUM ( case when CAT_MGR = 'A' THEN 1 else 0 end ) AS DESIGN, sum (case when CAT_MGR = 'b' THEN 1 else 0 END) AS DESIGN, sum (case when CAT_MGR = 'c' THEN 1 else 0 END) AS DESIGN from Table_A GROUP BY CAT_MGR
Can you guys help me I’m a beginner at SQL.
Thank you in advance
Advertisement
Answer
If you want just one row in the resultset, then remove the group by
clause. Then, if you want to count the three cat mgr together, you can use in
:
select sum(case when cat_mgr = 'a' then 1 else 0 end ) as design_a, sum(case when cat_mgr = 'b' then 1 else 0 end ) as design_b, sum(case when cat_mgr = 'c' then 1 else 0 end ) as design_c, sum(case when cat_mgr in ('a', 'b', 'c') then 1 else 0 end ) as design from Table_a