user1374843
user1374843

Reputation: 95

How to use 2 Sums in 1 select statement?

I would like to get the sums of 2 rows of 2 separate tables in one query. I tried this:

SELECT SUM(Items.Price) AS [Total Items], SUM(Stores.Cash) AS [Total Cash]
FROM Items, Stores

However, the query returns the sum of Price * number of stores and total cash in stores * number of items. What went wrong?

Upvotes: 2

Views: 107

Answers (1)

Alker
Alker

Reputation: 61

Use this

SELECT SUM(Price) AS [Total Items]
     , (SELECT SUM(Cash) AS [Total Cash] FROM Stores)
FROM Items

Upvotes: 6

Related Questions