Identify max dated records at a point in time

时间:2016-07-11 22:55:36

标签: sql teradata

I'm trying to identify the latest records in a DB for days in the past. The DB has Columns:

Record ID, AccNum, PersonNum, Start Date, End Date

Let's say for AccNum 123 and PersonNum 246 they have records for start & end dates:

Record ID 1 Start Date 18-Jun-16 End Date 19-Jun-16
Record ID 2 Start Date 19-Jun-16 End Date 23-Jun-16
Record ID 3 Start Date 24-Jun-16 End Date 26-Jun-16

I want the query to tell me the max dated record for a particular day. Eg on the 20th of Jun it would be Record ID 2, on the 25th of Jun it would be Record ID 3, for the AccNum and Person Num combination 123-246.

0 个答案:

没有答案