【发布时间】:2021-12-21 21:19:49
【问题描述】:
SQL 查询:针对每个部门,查找该部门教师的最高薪水。
Instructor schema: Instructor(ID , name, dept_name, Salary) Id 主键,dept_name 外键引用部门。
部门(部门名称、建筑、预算)
导师表值:
ID Iname dept_name salary
10101 Srinivasan Comp. Sci. 65000
12121 Wu Finance 90000
15151 Mozart Music 40000
22222 Einstein Physics 95000
32343 El Said History 60000
33456 Gold Physics 87000
45565 Katz Comp. Sci. 75000
58583 Califieri History 62000
76543 Singh Finance 80000
76766 Crick Biology 72000
83821 Brandt Comp. Sci. 92000
98345 Kim Elec. Eng. 80000
如果我们尝试手动找出最高薪水,
Brandt Comp. Sci
Wu Finance
Mozart Music
Einstein Physics
Califieri History
Crick Biology
Kim Elec. Eng.
现在我运行这个查询,
select distinct
T.Iname,
T.dept_name
from instructor as T,
instructor as S
where T.salary > S.salary
group by T.dept_name;
我明白了
Kim Elec. Eng.
Brandt Comp. Sci.
Crick Biology
Singh Finance
Gold Physics
Califieri History
我的金融和物理结果不正确,甚至音乐也没有包括在内。
我找不到我的错误。我想知道哪里需要修改?
谢谢。
【问题讨论】: