mysql - Aggregate function after having clause -
considering have following schema:
emp(eid:integer, ename:string, age:integer, salary:real) works(eid:integer, did:integer, pct_time:integer) dept(did:integer, budget:real, managerid:integer)
the question asks "if manager manages more 1 department, or controls sum of budgets departments. find managerids of managers control more $5 million." wrote following queries problem:
version 1:
select d.managerid department d group managerid having (select sum(d2.budget) department d2 d.managerid = d2.managerid) > 5000000
version 2:
select d.managerid department d group managerid having sum(d.budget) > 5000000
i know difference between above 2 queries? nested select statement required having clause?
edit: version 1 redundant since group by keyword allows sum function return sum of department budgets each manager?
Comments
Post a Comment