try this:
select employee,code,sum(anount)
from Table_data
group by employee, code
Main Topics
Browse All TopicsDtl_table
---------
employee
date
type
code
amount
DATA:
1234,01-01-03,ME,SETOPT,4
1234,01-01-03,LE,SETOPT,2.
1234,01-01-03,M ,SETOPT,3.20
1234,01-01-03,X ,SETOPT,1
Sum_table
---------
employee
code
YTD_amount
DATA:
1234,SETOPT,10.75
I need a report that looks like
Employee Date ME LE M X YTD
-------- -------- ---- ---- ---- ---- -----
1234 01-01-03 4.00 2.55 3.20 1.00 10.75
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try this:
select employee, date, sum(TA.me) as sum_me,
sum(TA.le) as sum_le,
sum(TA.m) as sum_m,
sum(TA.x) as sum_x,
sum(TA.ytd) as sum_ytd
from (
select employee, date, code
decode(type,'ME',amount,0)
decode(type,'LE',amount,0)
decode(type,'M',amount,0) as m,
decode(type,'X',amount,0) as x,
amount as ytd
from dtl_table
) TA
group by TA.employee, TA.date,TA.code
The output you are asking for is a classic "matrix" or "cross-tab" report. Standard SQL does not produce this kind of output by default. Oracle Reports (and other third-party reporting tools) can do this quite easily. Your other option is to use "decode" like others have already suggested. The disadvantage of the "decode" approach is that you have to know (and code for) all of the possible values in advance. The reporting tools can do this dynamically.
Business Accounts
Answer for Membership
by: andrewstPosted on 2003-03-26 at 13:39:28ID: 8213551
select employee, date, t,0)) me, t,0)) le, ,0)) m, ,0)) x,
sum(decode(type,'ME',amoun
sum(decode(type,'LE',amoun
sum(decode(type,'M',amount
sum(decode(type,'X',amount
sum(amount) ytd
from dtl_table
where code='SETOPT'
group by employee, date;
2 comments:
1) sum_table is redundant, you don't need it
2) you can't have columns called DATE or TYPE in Oracle, as they are reserved words