sql - What would be the result of the following query? -


enter image description here

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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -