Oracle select most recent date record

后端 未结 4 1785
我在风中等你
我在风中等你 2020-12-16 16:15

I am trying to find the most recent record based on a date field. When I set latest = 1 in the where clause, I get an error. Please help if possible. DATE is a the field I

4条回答
  •  醉酒成梦
    2020-12-16 16:45

    Assuming staff_id + date form a uk, this is another method:

    SELECT STAFF_ID, SITE_ID, PAY_LEVEL
      FROM TABLE t
      WHERE END_ENROLLMENT_DATE is null
        AND DATE = (SELECT MAX(DATE)
                      FROM TABLE
                      WHERE staff_id = t.staff_id
                        AND DATE <= SYSDATE)
    

提交回复
热议问题