|
|
Archives of the TeradataForum
Message Posted: Thu, 27 Aug 2009 @ 22:17:33 GMT
Subj: | | Re: Easy way to get the latest updated row in a query |
|
From: | | Dieter Noeth |
cblake wrote:
| What I'm looking for is the easiest / fastest way to pull the row with the > most recent timestamp number. | |
It's OLAP time again :-)
select i.logicalKey1
,i.logicalKey2
,i.logicalKey3
,max(i.desiredAttribute) as chosenDesiredAttribute
from table i
group by 1,2,3
qualify
rank() over
(partition by logicalKey1
, logicalKey2
, logicalKey3
order by timeStampKey1,sequenceNbrKey1) = 1
Instead of GROUP BY you you might add i.desiredAttribute to the order by:
select i.logicalKey1
,i.logicalKey2
,i.logicalKey3
,i.desiredAttribute
from table i
qualify
rank() over
(partition by logicalKey1
, logicalKey2
, logicalKey3
order by timeStampKey1,sequenceNbrKey1,i.desiredAttribute) = 1
Dieter
| |