SELECT deptno, AVG(sal) FROM emp GROUP BY deptno ORDER BY 2 DESC;
SELECT deptno, AVG(sal) AS "priemerny plat" FROM emp GROUP BY deptno ORDER BY "priemerny plat" DESC;
odd_avg_plat(DN,A):- dept(DN,_,_),subtotal(emp(_, _, _, _, _, S, _, DN), [DN], [avg(S, A)]).
% musime viazat premenu, podla ktorej agregujeme. A v datalogu nesortujeme.