Group by more than one field

capsula4

Registered User.
Local time
Today, 15:40
Joined
Jan 3, 2008
Messages
122
Hi!

I would like to know how GroupBy works. I have a 1-many relationship (invoice-products)

I have this query:

[OPERATION_ID], DESCRIPTION: [PRODUCT NAME] & [PRODUCT TYPE], [QUANTITY]

What I would like is to have a group by DESCRIPTION since some products may be repeated in a same OPERATION cuz they are from dif origin but in the invoice they gotta be merged.

So if I have:

1 | GARLIC WHITE | 20
1 | GARLIC WHITE | 20
1 | ONION RED | 20
2 | GARLIC WHITE | 20
2 | POTATOE RED | 20

The query should return

1 | GARLIC WHITE | 40
1 | ONION RED | 20
2 | GARLIC WHITE | 20
2 | POTATOE RED | 20

With this I mean: If DESCRIPTION (product and product type) are the same, group them Per OPERATION_ID and Sum QUANTITIES
 
Group by both Invoice_ID and DESC (which is a bad name for a field, since it's a reserved word).
 
Thanks pbaldy!!

Actually I changed DESC to DESCRIPTION. My doubt is once I group by those 2 fields, what happen with the amounts? I want them to become summed, how shall I indicate it? Or is it enough as you have already told me?
 
Thanks for not answering!

I just investigated a bit on it and also tried dif options with the SQL summary functions, I didn't really understand how they worked but now since I played a bit with em I got it.

Thanks! :D
 
I was sound asleep!

Glad you got it sorted out.
 

Users who are viewing this thread

Back
Top Bottom