Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Write Select Query using Sum and maybe Distinct 1

Status
Not open for further replies.

UncleCake

Technical User
Feb 4, 2002
355
US
Hi,

I have data that looks like the following:

Inv Num Item Num Qty Location
H100 TT3456 5 L199
H100 OG5050 9 L123
H100 OG5050 6 L123
H100 TT3456 6 L199
H100 OG5050 5 L123

What I need to do is sum the Qty where the Location is the same.

This is my current SELECT statement:

SLELECT InvNum, ItemNum, Qty, Location
FROM InvoiceItems
WHERE Invoice = 'H100'

This will return all of the line items individually. I would like it to return this:

H100 OG5050 20 L123
H100 TT3456 11 L199

I assume that I would use the SUM function and maybe GROUP or DISTINCT, but I can't figure it out.

-Uncle Cake

 
Code:
SLELECT InvNum, ItemNum, SUM(Qty), Location
FROM InvoiceItems
WHERE Invoice = 'H100'
group by InvNum,ItemNum,Location
 
Oh, I have to group all fields that are the same. I wasn't doing that. I only grouped the Location.

Thanks for your help!

-Uncle Cake
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top