MS$DesignersRCretins
Registered User.
- Local time
- Today, 01:24
- Joined
- Jun 6, 2012
- Messages
- 41
I'd like to do a grouping query as follows. The source table has three numbers per record.
I would like to do a query that groups field A;
gives the max for field B;
gives the field C that corresponds to the max B for each A. That is, I WANT:
1 100 11
2 60 22
since those are the max B's. But if I go
SELECT A, Max(B), C
all 4 original records are returned, because I'm grouping C.
How can I get C in the output, but just the ones corresponding to max B?
All I can come up with is doing 2 passes:
select a,max(B)
and then left or right joining that output to the source table, thus preventing e.g. 1 50 17 from consideration.
Is there a more direct way?
Sorry for the lame thread title. I didn't know how to describe it succinctly.
Code:
A B C
1 50 17
1 100 11
2 30 55
2 60 22
gives the max for field B;
gives the field C that corresponds to the max B for each A. That is, I WANT:
1 100 11
2 60 22
since those are the max B's. But if I go
SELECT A, Max(B), C
all 4 original records are returned, because I'm grouping C.
How can I get C in the output, but just the ones corresponding to max B?
All I can come up with is doing 2 passes:
select a,max(B)
and then left or right joining that output to the source table, thus preventing e.g. 1 50 17 from consideration.
Is there a more direct way?
Sorry for the lame thread title. I didn't know how to describe it succinctly.
Last edited: