Oracle
SUM + DECODE + TO_CHAR
Figo Kim
2006. 8. 31. 20:13
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