Link to home
Start Free TrialLog in
Avatar of HawaiiDragon
HawaiiDragon

asked on

Doing a count and sum in SQL query

Hello all,

 I of course am having problems with something that I am sure is simple as heck. I have my qurey ahat returns vendor names and payments from a table now I have come to the hard part. I need the totals of the payments based off of vendors in the payment sum collum. ie company A has paid 10 , 2 , 5 so the result would say Company A 17

Thank you for your assistance

SELECT     TOP (10) Vendors.VendorName, Invoices.PaymentTotal  As PaymentSum
FROM         Invoices INNER JOIN
                      Vendors ON Invoices.VendorID = Vendors.VendorID

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Rajkumar Gs
Rajkumar Gs
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HawaiiDragon
HawaiiDragon

ASKER

Thank you so much you pushed me in the right direction. Here is the finished code.

 
                      SELECT   TOP (10)  Vendors.VendorName,
SUM(Invoices.PaymentTotal)  As PaymentSum
FROM         Invoices INNER JOIN
                      Vendors ON Invoices.VendorID = Vendors.VendorID
GROUP BY Vendors.VendorName
Order by PaymentSum DESC
Glad to help you :)
Raj