angellll,
I have missed to include the GROUP BY statement while editing the SELECT to post it here.
But I do have the GROUP BY in inner select and the SUM I refer to is used with COMPUTE, not with the Select statement
Main Topics
Browse All TopicsMy select statement looks something like below and I have to use Over Partition by with Rownum as there are duplicates with a_id.
When I try to do a COMPUTE SUM on Cost column it also considers duplicate values from a_id
Is there any way I can avoid duplicates in COMPUTE SUM
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.
BREAK ON a_id dup-
ON cat DUP -
ON description DUP -
ON l dup -
ON t dup -
ON s dup -
ON cost -
ON c -
ON y -
ON l -
ON n -
ON s -
ON REPORT
COL l FORMAT 999
COL cost FORMAT 999,999,999,999.99
COL c FORMAT 999,999,999,999.99
COL y FORMAT 999,999,999,999.99
COL l FORMAT 999,999,999,999.99
COL n FORMAT 999,999,999,999.99
COL s FORMAT 999,999,999,999.99
compute sum of cost on report FORMAT 999,999,999,999.99
SELECT a1.cat,
a1.description,
a1.a_id,
a1.l,
a1.t,
a1.s,
a1.cost,
a1.c,
a1.y,
a1.l,
a1.n,
a1.s,
a1.v,
a1.lc
FROM (SELECT cat,
a_id,
description,
TO_CHAR (dated, 'MM/DD/YYYY') a,
l,
t,
s,
dd.cost,
ROW_NUMBER ()
OVER (PARTITION BY aid ORDER BY dd.cost DESC)
cnt,
c,
y,
l,
n,
s,
v,
lc
FROM listoftables) a1
WHERE a1.cnt = 1
group by
cat,a_id,description,dated
dd.cost,c,y,l,n,s, v,lc
ORDER BY 1, 2, 3;
Data in DB - tables
a_id Cost
1 4000
1 4000
2 2000
2 2000
3 3000
Since I have a ROWNUM=1 on a_id it only returns
a_id Cost
1 4000
2 2000
3 3000
When I do a compute sum of cost on report FORMAT 999,999,999,999.99 I want the program to return SUM based on the output of my query
which would be 9000, instead its doing a sum on the table data and returning 15000
Thanks for your help
Business Accounts
Answer for Membership
by: angelIIIPosted on 2009-08-02 at 04:24:34ID: 24998474
you have to group by in a subselect first, so you don't have the "duplicates" when doing the SUM() ..