[Solved] SQL and Counting


Give this a try:

select name,
    count(case when grade in ('A', 'B', 'C') then 1 end) totalPass,
    count(case when grade="A" then 1 end) totalA,
    count(case when grade="B" then 1 end) totalB,
    count(case when grade="C" then 1 end) totalC
from t
group by name

Here is the fiddle.

Or we can make it even simpler if you were using MySQL:

select name,
    sum(grade in ('A', 'B', 'C')) totalPass,
    sum(grade="A") totalA,
    sum(grade="B") totalB,
    sum(grade="C") totalC
from t
group by name

Here is the fiddle.

3

solved SQL and Counting