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

HawaiiDragonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rajkumar GsSoftware EngineerCommented:
Did I understand your requirement right ? - Please check this query. As your question title asks, this query should return SUM and COUNT
SELECT     Vendors.VendorName, 
SUM(Invoices.PaymentTotal)  As PaymentSum,
COUNT(Invoices.PaymentTotal)  As PaymentCount
FROM         Invoices INNER JOIN
                      Vendors ON Invoices.VendorID = Vendors.VendorID
GROUP BY Vendors.VendorName

Open in new window


Raj
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HawaiiDragonAuthor Commented:
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
0
Rajkumar GsSoftware EngineerCommented:
Glad to help you :)
Raj
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.