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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Top 3 sales totals by contact

Useful SQL Queries

Top 3 sales totals by contact

by  goner  Posted    (Edited  )
Substitute the 3 in the first line to see more than the top 3...

SELECT TOP 10
c1.company
,c1.contact
,SUM(CAST(ch.duration AS MONEY)) AS TotalSales
,COUNT(ch.duration) AS SalesCount
,ch.accountno
FROM
contact1 c1
JOIN conthist ch
ON c1.accountno=ch.accountno
WHERE
ch.srectype = 'S'
GROUP BY
c1.contact
,c1.company
,ch.accountno
ORDER BY
SUM(CAST(ch.duration AS MONEY)) DESC
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top