Oracle

SUM + DECODE + TO_CHAR

Figo Kim 2006. 8. 31. 20:13
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
SELECT  COUNT(*) total,
SUM(DECODE(TO_CHAR(hire_date, 'YYYY'),1995,1,0))"1995",
SUM(DECODE(TO_CHAR(hire_date, 'YYYY'),1996,1,0))"1996",
SUM(DECODE(TO_CHAR(hire_date, 'YYYY'),1997,1,0))"1997",
SUM(DECODE(TO_CHAR(hire_date, 'YYYY'),1998,1,0))"1998"
FROM employees;


Make it sure that you will check this question again!!!!

This sql statement is very similar with the previous one.
select
job_id as "Job",
sum(decode(department_id,20,salary,null)) as "Dept20",
sum(decode(department_id,50,salary,null)) as "Dept50",
sum(decode(department_id,80,salary,null)) as "Dept80",
sum(decode(department_id,90,salary,null)) as "Dept90",
sum(salary) as "Total"
from
employees
group by
job_id
order by
job_id




'Oracle' 카테고리의 다른 글

INNER join vs OUTER joins  (0) 2006.09.01
INNER join vs OUTER joins  (0) 2006.09.01
SUM + DECODE + TO_CHAR  (0) 2006.08.31
Restricting Group Results  (0) 2006.08.31
Restricting Group Results  (0) 2006.08.31