Reputation: 171
I am currently getting executing a select statement. I just want to get a sum of one of the rows and not the other 3. I have the following:
SELECT SUM([Amount]), [Number], [Brand]
FROM [myTable]
WHERE [ID] = '1000'
I just want to get the sum of Amount. If I take out Number and Brand and only select Amount it works great, but not with them included... any ideas?
SELECT SUM([Amount]), [Number], [Brand]
FROM [myTable]
WHERE [ID] = '1000'
Upvotes: 0
Views: 3875
Reputation: 458
You are probably getting an error because the other selections are not being used in an aggregate function.
To resolve you may want to try grouping, something like this:
SELECT SUM(Amount) AS Amount, Number, Brand
FROM [yourtable]
WHERE ID = 1000
GROUP BY Number, Brand
Upvotes: 1
Reputation: 4043
You need to group it.
SELECT
SUM([Amount]), [Number], [Brand]
FROM
[myTable]
WHERE
[ID] = '1000'
GROUP BY
Number , Brand
Upvotes: 5