D
Dave
Is it possible to query out the min date for each time a data element changes?
Thanks
Dave
Thanks
Dave
= Q.[Code])+1 AS Rank, (SELECT COUNT(*) FROM [Dave] Q2
WHERE Q2.[Date] < Q.[Date]
AND Q2.[Code] < Q.[Code])+1 AS Rank1
FROM Dave AS Q
ORDER BY Q.Date, Q.Code;
SELECT DaveCodeList.Date, DaveCodeList.Code
FROM DaveCodeList
WHERE (((DaveCodeList.Rank1)=[Rank]));
Data example:
DATE CODE
8/8/1990 P
8/30/1990 P
9/26/1994 C
11/16/1994 P
4/10/1995 A
5/30/1995 A
5/4/2009 P
I want to show the min DATE for each change in CODE.
I tried By Group but the result showed the min DATE for "P" but not where
the CODE changed to "P" again.
The result should be:
DATE CODE
8/8/1990 P
9/26/1994 C
11/16/1994 P
4/10/1995 A
5/4/2009 P
John Spencer said:I'm not sure this will work, but you can try the following solution
First Query (Saved as QRank):
SELECT A.Date, A.Code, Count(B.Date) as Rank
FROM [Your Table] as A LEFT JOIN [Your Table] As B
ON A.Date > B.Date
GROUP BY A.Date, A.Code
Second Query:
SELECT A.Date, A.Code
FROM QRank as A LEFT JOIN QRank as B
ON A.Rank = B.Rank -1
WHERE A.Code <> B.Code
OR B.Code is Null
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
Thank you for the queries...but they still give only the earliest date that
say "P" occurs and not the earliest dates when the CODE changes to "P"
throughout the ordered DATE field.
The order of the DATE field is relevant in that the CODE can change from "P"
to "C" then to "P" again, which is important.
Does the table need another field that make the DATE, CODE fields unique?
Dave
John Spencer said:I'm not sure this will work, but you can try the following solution
First Query (Saved as QRank):
SELECT A.Date, A.Code, Count(B.Date) as Rank
FROM [Your Table] as A LEFT JOIN [Your Table] As B
ON A.Date > B.Date
GROUP BY A.Date, A.Code
Second Query:
SELECT A.Date, A.Code
FROM QRank as A LEFT JOIN QRank as B
ON A.Rank = B.Rank -1
WHERE A.Code <> B.Code
OR B.Code is Null
'====================================================
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
Thank you for the queries...but they still give only the earliest date that
say "P" occurs and not the earliest dates when the CODE changes to "P"
throughout the ordered DATE field.
The order of the DATE field is relevant in that the CODE can change from "P"
to "C" then to "P" again, which is important.
Does the table need another field that make the DATE, CODE fields unique?
Dave
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.