pape
pape

Reputation: 239

SQL - sum of column

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:

enter image description here

but I want the output is sum of Quantity 10+5=15

enter image description here

Upvotes: 0

Views: 275

Answers (2)

Chris
Chris

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

Jeroen Bellemans
Jeroen Bellemans

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

Related Questions