Tuesday, May 24, 2011

CASE WHEN

--- USE OF case when
--- IT WILL COUNT THE NUMBER OF EMP WHO GET SALARY BETWEEN
--- 0 TO 3000 AND 3001 TO 10000


select
SUM(CASE WHEN SUM(SAL)
BETWEEN 0 AND 3000
THEN 1 ELSE 0 END) AS "0-3000",
SUM(CASE WHEN SUM(SAL)
BETWEEN 3001 AND 10000
THEN 1 ELSE 0 END) AS "3001-10000"
from SCOTT.EMP
group by SAL

No comments:

Post a Comment