SQLTeam.com | Weblogs | Forums

How can I get a sum but only of distinct records


#1

MY query is

SELECT distinct affiliate_date,affiliate_orders_id,affiliate_value,affiliate_payment,affiliate_percent,typeofsale FROM affiliate_sales

now I want to get the sum of these records
so the sum of (affiliate_sales) only for the distinct records

how can I do this?


#2

Please provide:

  • table descriptions as create statements
  • sample data as insert statements
  • expected output from the sample data you provide

#3
SELECT SUM ( affiliate_value ) ,  . . . .
FROM
(
    SELECT distinct 
           affiliate_date,affiliate_orders_id,affiliate_value,affiliate_payment,affiliate_percent,typeofsale
    FROM   affiliate_sales 
) AS D