Re: Group By, Max and Min
- From: "Michel Walsh" <vanderghast@VirusAreFunnierThanSpam>
- Date: Mon, 10 Mar 2008 14:41:29 -0400
What happen if info for the record with the min value differs from info from
the record for the max? which info value will we keep? If info is the same
for all records GIVEN field1, field2 and field3, then use:
SELECT field1, field2, field3, LAST(info), MIN(time), MAX(time)
FROM query
GROUP BY field1, field2, field3
ORDER BY field1, field2, field3
If 'info' is not the same for all record, you are likely having two
different values (one associated to min, one to max) and that is why your
actual design cannot be further reduced (in number of rows), unless you
carry info_min and info_max, two info values, in the final result, as two
fields (un-normalized result look ).
Hoping it may help,
Vanderghast, Access MVP
"Aino" <aij@xxxxxxxxx> wrote in message
news:5fb5ed80-603f-4f0d-80e6-1e6f5b5f7b41@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am struggling with a query, and need help
I have (from a previous saved query) these fields:
Field1, Field2, Field3, Time, Info
What I want to return is the maximum and minimum time along with the
corresponding infos, grouped by the first 3 fields:
Field1, Field2, Field3, Min(Time), Max(Time), InfoForMinTime,
InforForMaxTime
Sofar I have
SELECT T1.Field1, T1.Field2, T1.Field3, T1.Info, Min, Max
FROM [Query] AS T1 INNER JOIN
(SELECT Field1, Field2, Field3, Max(Time) AS Max, Min(Time) AS Min
FROM [Query]
GROUP BY Field1, Field2, Field3) as T2
ON T1.Field1= T2.Field1 AND T1.Field2=T2.Field2 AND
T1.Field3=T2.Field3 AND (T1.Time = T2.Max OR T1.Time=T2.Min)
ORDER BY Field1, Field2, Field3;
Obviously, I only get one Info field from this, and twice as many
records as I want, identical 2 and 2 apart from the Info field.
.
- Follow-Ups:
- Re: Group By, Max and Min
- From: Aino
- Re: Group By, Max and Min
- References:
- Group By, Max and Min
- From: Aino
- Group By, Max and Min
- Prev by Date: Re: How do I temporarily limit values in a query field
- Next by Date: RE: Number of paychecks within the year
- Previous by thread: Group By, Max and Min
- Next by thread: Re: Group By, Max and Min
- Index(es):
Relevant Pages
|
Loading