MAX(DATE) - SQL ORACLE

前端 未结 5 2007
感动是毒
感动是毒 2021-02-20 03:03

I want to select only the latest membership_id from table user_payments of the user with the user_id equal to 1.

This is how the table user_payment looks like:



        
5条回答
  •  清歌不尽
    2021-02-20 03:23

    SELECT p.MEMBSHIP_ID
    FROM user_payments as p
    WHERE USER_ID = 1 AND PAYM_DATE = (
        SELECT MAX(p2.PAYM_DATE)
        FROM user_payments as p2
        WHERE p2.USER_ID = p.USER_ID
    )
    

提交回复
热议问题