shin
shin

Reputation: 3649

SQL group per class and rate

Please help me. I've been making a report where I need to count how many got the specific rate per class and how many specific class per rate. Is my desired output even possible? Please do advise me for better solutions. Thanks much.

=Desired Ouput

enter image description here

Used Query (Which generates wrong output)

SELECT COUNT(job_class), 
job_class, finalrate 
FROM t GROUP by job_clas

See my SQL FIDDLE

Upvotes: 0

Views: 27

Answers (1)

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

Use conditional aggregation.

SQL Fiddle

SELECT 
job_class, 
sum(case when finalrate like 'A%' then 1 else 0 end) as AA,
sum(case when finalrate like 'B%' then 1 else 0 end) as B,
sum(case when finalrate like 'C%' then 1 else 0 end) as C
FROM t 
GROUP by job_class

Upvotes: 2

Related Questions