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?
 
Rajkumar GsConnect With a Mentor Software 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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.