Monday, 17 October 2011

There are two tables namely EMP, SALGRADE

Fields of SALGRADE are
GRADE, LOSAL HISAL
Fields of EMP table are as usual
I want the output like this.

GRADE LOSAL HISAL COUNT (*)
--------- --------- --------- ---------
1 700 1200 4
2 1201 1400 5
3 1401 2000 4
4 2001 3000 8
5 3001 9999 2

Select grade, losal, hisal, count (*) from EMP, salgrade
Where sal between losal and hisal
Group by grade, losal, hisal

4 comments:

  1. HOW TO FIND AVGSAL OF LOSAL AND HISAL IN SALGRADE

    ReplyDelete
  2. --Abhishek Rao Maidarkar
    SELECT DISTINCT S.*, COUNT(*) OVER (PARTITION BY GRADE ORDER BY GRADE) FROM EMP E, SALGRADE S
    WHERE E.SAL BETWEEN S.LOSAL AND S.HISAL
    ORDER BY S.GRADE

    ReplyDelete
  3. --Abhishek Rao Maidarkar --For avareage salary
    SELECT DISTINCT S.*, AVG(SAL) OVER (PARTITION BY GRADE ORDER BY GRADE) FROM EMP E, SALGRADE S
    WHERE E.SAL BETWEEN S.LOSAL AND S.HISAL
    ORDER BY S.GRADE

    ReplyDelete