Reputation: 10395
I have a table that contains an orderid
, an inventoryid
, and a quantity
-- its a line items table. The database is SQL Server 2008.
What I need to know is how to write a SQL statement that returns the sums of quantities for that itemid
at that order, not counting orders that have larger orderids
than it. It must return the orderid
, itemid
, and total
.
Any help? Thanks!
Upvotes: 1
Views: 4204
Reputation: 432230
Guess:
SELECT
SUM(quantity) AS total, --"sums of quantities for that itemid at that order"
orderid, inventoryid --"It must return the orderid, itemid"
WHERE
orderid < (some larger order id value) --"not counting orders that have larger orderids"
GROUP BY
orderid, inventoryid
Upvotes: 1