## Ebay Interview Question

Software Engineer / DevelopersWhy do we need group by, how about

select

(select Sum(sal) from emp where sal=(select Max(sal)from emp)) -

(select Sum(sal) from emp where sal=(select Min(sal)from emp))

from dual;

`select sum(sal) keep (dense_rank first order by sal asc) over (partition by dept) total_min_sal, sum(sal) keep (dense_rank last order by sal asc ) over (partition by dept) total_max_sal,emp.* from emp`

the following is the perfect query ....

- gullu October 15, 2010select

(select Sum(sal) from emp group by sal having sal=(select Max(sal)from emp)) -

(select Sum(sal) from emp group by sal having sal=(select Min(sal)from emp))

from dual;