select e.deptno,s.grade,sum(sal)
from emp e , salgrade s
where (e.sal between s.losal and s.hisal)
group by e.deptno,s.grade
order by e.deptno,s.grade;
我无法在查询中显示缺少成绩的0工资
答案 0 :(得分:1)
从不在FROM
子句中使用逗号。 始终使用正确的,明确的,标准 JOIN
语法。
您想要一个LEFT JOIN
。假设您拥有所有部门的表:
select d.deptno, s.grade, sum(e.sal)
from departments d left join
emp e
on e.deptno = d.deptno left join
salgrade s
on e.sal between s.losal and s.hisal
group by d.deptno, s.grade
order by d.deptno, s.grade;