Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 re: query almost solved apart from total?

Author  Topic 

msa969
Starting Member

13 Posts

Posted - 2001-10-29 : 11:50:40
This query calculates all column apart from total,

i.e.

@p5q12ii.sql

JOB Dept 10 Deptno 30 Dept 30 Total
--------- ---------- ---------- ---------- ----------
ANALYST 6000
CLERK 1300 1900 950
MANAGER 2450 2975 2850
PRESIDENT 5000
SALESMAN 5600

This is the code

select job,sum(decode(deptno, 10,sal)) "Dept 10", sum(decode(deptno,20,sal))
"Deptno 30", sum(decode(deptno,30,sal)) "Dept 30",
sum(decode(deptno,10,sal)+decode(deptno,20,sal)+decode(deptno,30,sal)) "Total" from emp group by job;

I am stumped why it does'nt work.

Please help.

   

- Advertisement -