Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem getting sum of distinct entries

Status
Not open for further replies.

morfasie

IS-IT--Management
Mar 28, 2004
85
ZA
I have a table with policy values. But some of them are in the table more than once. I have to sum the Premium amount don't know how to calc the sum for distinct values?

Can anybody please help

Thanks
martin
 
Something like this ?
SELECT policy, SUM(PremiumAmount) AS PremAmt
FROM theTable
GROUP BY policy

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi thanks,
that is fine if you have one entry per policy, but I have multiple and only want to do a sum of premium on the distinct ones.

 
Code:
SELECT 
  policy
, SUM(PremiumAmount) PremAmt
FROM 
  (select distinct policy, PremiumAmount from theTable)
GROUP BY policy
 
ANSI SQL supports:

SELECT
policy
, SUM(DISTINCT PremiumAmount)
FROM
my_table
GROUP BY policy

Dieter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top