我试图找到管理人员的名字,他们只管理预算超过100万的部门,但至少有一个预算少于500万的部门
我知道查询应该像这样工作但不能让它在Mysql中运行。我猜测因为Every和Any在mysql中不起作用。有没有其他方法来写这个?这里还有架构
Emp(eid: integer, ename: string, age: integer, salary: real)
Works(eid: integer, did: integer, pct_time: integer)
Dept(did: integer, dname: string, budget: real, managerid: integer)
以下是查询:
select
e.ename
from
emp e, dept d
where
e.eid=d.managerid
group by
e.eid, e.ename
having
every(d.budget>1000000) and
any(d.budget<5000000);
答案 0 :(得分:3)
SELECT e.ename
FROM emp e
JOIN dept d
ON e.eid = d.managerid
GROUP BY e.eid,
e.ename
HAVING MIN(d.budget) > 1000000
AND MIN(d.budget) < 5000000;