sql - What would be the result of the following query? -
the following query tried...
select d.deptid, max(tt.total) dept d, (select d.deptid, d.deptname, sum(days) total vacation v, employee e, dept d v.empid = e.empid , d.deptid = e.deptid group d.deptid, d.deptname) tt d.deptid = tt.deptid group d.deptname; --having max(tt.total);
try using limit since inner query calculation.
select top 1 * ( select d.deptid, d.deptname, sum(days) total vacation v, employee e, dept d v.empid = e.empid , d.deptid = e.deptid group d.deptid, d.deptname) order total desc;
depends on dbms you're using.. mysql
in oracle use rownum = 1
in sql server use select top 1 *
Comments
Post a Comment