MySQL Forums
Forum List  »  Newbie

Calculate sum of distinct Rows
Posted by: Monique Leonard
Date: March 23, 2006 03:34PM

I’m trying to extract distinct rows and the sum of a certain column of only those rows from a table. For example, given the MySQL statement:

select DECISION, count(distinct B_SSN, APP_DT), sum(REQUESTED_AMT) from table where APP_DT >= '20060322' and APP_DT <= '20060322' group by DECISION

With the table below:

DECISION – B_SSN – REQUESTED_AMT – APP_DT
PASS - 111111111 – 20000 - 20060322
PASS - 111111111 - 20000 - 20060322
PASS - 222222222 – 12000 - 20060322
PASS - 333333333 - 1200 - 20060322

Gives me this:
PASS – 3 – 53200

Whereas I’m looking for this:
PASS – 3 – 33200

Any tips or suggestions for getting SUM to act the way I want it to? Can it act that way? Am I going to have to retrieve all distinct rows and calculate this manually?

Thanks very much for any help you might offer.

Options: ReplyQuote


Subject
Written By
Posted
Calculate sum of distinct Rows
March 23, 2006 03:34PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.