Wednesday, October 23, 2013

Sub queries in Having Clause oracle




SELECT Deptno, MIN(Sal)
FROM Emp
GROUP BY Deptno
HAVING  MIN(Sal) > (SELECT
                    MIN(Sal)
                    FROM Emp
                    WHERE  Deptno = 20);
                   
SELECT Job, AVG(Sal)
FROM Emp
GROUP BY Job
HAVING AVG(Sal) =  (SELECT
                    MIN(Avg(Sal))
                    FROM Emp
                    GROUP BY Job);

SELECT Job, AVG(Sal)
FROM Emp
GROUP BY Job
HAVING AVG(Sal) < (SELECT
                    MAX(AVG(Sal))
                    FROM Emp
                    GROUP BY Job);

SELECT Job, AVG(Sal),
TO_CHAR(AVG (Sal), 'L99,999.99')
FROM Emp
GROUP BY Job
HAVING  AVG(Sal) < (SELECT
MAX(AVG(Sal))
FROM Emp
GROUP BY Deptno);  

1 comment:

Nasreen Basu said...

very useful really good information thanks for posting such a good information it will hepls the people a lot keep it up , Regards, obiee training in hyderabad

Post a Comment

Best Blogger TipsGet Flower Effect