Why is this regarded as incorrect GROUP BY usage?
SELECT Empno, Deptno,
SUM(Sal) "Total"
FROM Emp
GROUP BY Deptno;
The result given in my notes is:
Empno Deptno Total ------- ------ -------- ? 10 8750 ? 20 10875 ? 30 9400
with the reason of:
All columns in SELECT
list must either appear in
GROUP BY or be
aggregated!
But I’m not too sure what it means…
Since both Empno and Deptno are selected, you need to group by both fields:
or just select Deptno if Empno isn’t used: