C
CJ_DB
Hey folks,
Hope to recieve a little help Here. I need to return all the fields of a
record of data where the selection criteria and the aggregation is
questionable. Example:
IDN YRMODAY PCT REG DIST
1 527479999 20021218 71 08 4
2 527479999 20060418 70 09 6
3 527479999 20040318 70 08 4
4 527479999 20041218 70 08 4
5 527479999 20060418 71 07 9
6 527479999 20041218 71 08 4
7 527479999 20040318 71 03 4
8 527479999 20060418 71 08 4
In the above set of records , I need to return the record with the most
recent date (yyyymmdd) <Max> with the highest PCT <Max> and all columns in
that row. In this case it would be Row 8 as the last value of the date
grouping. There are at 30 other columns that may have variant data. I am
currently using a Select query to find the Max date group by the IDN:
Select IDN, MAX(YR&MM&DD) as TDATE FROM Table1 Group By IDN
Use that result as join criteria for pulling MAX PCT:
Select IDN, TDATE, MAX(PCT) as TPCT, Last(REG) AS LREG, Last(DIST) as LDIST
FROM Table1 GroupBy IDN, TDATE
Notice rows 2,5,8 are same date and row 2 has different PCT so I need the
MAX(PCT). LREG and LDIST do not seem to always return the correct Row data.
Sometimes row 5 sometimes row 8. How can I be sure to pull all and only row
8. There are too many fields that are variant to Group by or Key on.
Long but hope this is enough information that I may recieve more
understanding of how the First, Last, and Max work and how to return the
correct row.
Tnx all
Hope to recieve a little help Here. I need to return all the fields of a
record of data where the selection criteria and the aggregation is
questionable. Example:
IDN YRMODAY PCT REG DIST
1 527479999 20021218 71 08 4
2 527479999 20060418 70 09 6
3 527479999 20040318 70 08 4
4 527479999 20041218 70 08 4
5 527479999 20060418 71 07 9
6 527479999 20041218 71 08 4
7 527479999 20040318 71 03 4
8 527479999 20060418 71 08 4
In the above set of records , I need to return the record with the most
recent date (yyyymmdd) <Max> with the highest PCT <Max> and all columns in
that row. In this case it would be Row 8 as the last value of the date
grouping. There are at 30 other columns that may have variant data. I am
currently using a Select query to find the Max date group by the IDN:
Select IDN, MAX(YR&MM&DD) as TDATE FROM Table1 Group By IDN
Use that result as join criteria for pulling MAX PCT:
Select IDN, TDATE, MAX(PCT) as TPCT, Last(REG) AS LREG, Last(DIST) as LDIST
FROM Table1 GroupBy IDN, TDATE
Notice rows 2,5,8 are same date and row 2 has different PCT so I need the
MAX(PCT). LREG and LDIST do not seem to always return the correct Row data.
Sometimes row 5 sometimes row 8. How can I be sure to pull all and only row
8. There are too many fields that are variant to Group by or Key on.
Long but hope this is enough information that I may recieve more
understanding of how the First, Last, and Max work and how to return the
correct row.
Tnx all