The other day, I gave an answer to this question but then other user solved that problem with sum + case conditional statement to add one edge condition in result. So, the q
Presumably, this is the part that you are struggling to understand:
select deptno,
sum(case when jobname = 'Analyst' then 1 else 0 end) as numAnalysts
from employees
group by deptno
This is a simple aggregation query, really. What the query is doing is:
employeesjobname is 'Analyst' then assign the value of 1 (this is the case statement. Otherwise, assign a value of0`.case is an expression that returns a value. The sum() is simply adding up that value for each group.