Reputation: 239
I'm trying to create a SQL query that will sum column that have the same No_. How can I sum the Quantity?
select Item.No_, Entry.[Posting Date], Entry.Quantity, MinMax.Maximum
FROM Item
join Entry
on Item.No_ = Entry.[Item No_]
join MinMax
on Item.No_ = MinMax.Item No_
The output:
but I want the output is sum of Quantity 10+5=15
Upvotes: 0
Views: 275
Reputation: 915
Try the following although without test information the group by may not be correct/ work as expected.
select Item.No_, Entry.[Posting Date], Sum(Entry.Quantity) as TotalQuantity, MinMax.Maximum
FROM Item
join Entry
on Item.No_ = Entry.[Item No_]
join MinMax
on Item.No_ = MinMax.Item No_
Group By Item.No_, Entry.[Posting Date], MinMax.Maximum
Upvotes: 1
Reputation: 2035
You can use the sum()
function:
SELECT sum(Entry.quantity) as sum_quantity
FROM Item
JOIN Entry ON Item.No_ = Entry.[Item No_]
JOIN MinMaxON Item.No_ = MinMax.Item No_
Upvotes: 0