Getting one entry per RANK
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Getting one entry per RANK Expand / Collapse
Author
Message
Posted 8/18/2006 11:44:10 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 10/4/2006 6:08:00 PM
Posts: 1, Visits: 1
I need to get the most recent records (based on date) for each ID. I cannot do a group by since there are too many non-aggregate values that I do not want to consider when grouping. I have tried:
rank() over partition by ID,modification date order by modification date (DESC)

However, when the dates are the same for more than one record for a specific ID I get the same rank. I only need to pull one record per id and date when rank =1.

Thanks

Carole
Post #4937
Posted 8/19/2006 1:26:26 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 6/25/2008 7:26:06 AM
Posts: 474, Visits: 202
Hi Carole,
just add more columns to the Order By to make it unique or use row_number instead of rank...

Dieter
Post #4942
Posted 4/9/2008 3:56:37 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 4/9/2008 4:16:39 PM
Posts: 1, Visits: 5
Carole,

I know this is an old post, but for those looking at this, try doing something like this.

select id_field, date_field, id2_field
from table1
where ...
qualify rank() over (partition by id_field order by id_field, date_field desc, id2_field desc) = 1

This will get the id_field for the max (rank = 1) date_field and exclude everything else where the rank isn't = 1 and the id2_field is a tie-breaker. If you don't have an id2_field, then you probably won't need a tie-breaker and you can simply exclude it from your query.

Enjoy!

tau

Post #11190
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 12:04am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.438. 9 queries. Compression Disabled.