MAX(DATE) - SQL ORACLE

前端 未结 5 2077
感动是毒
感动是毒 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:28

    Try:

    SELECT MEMBSHIP_ID
      FROM user_payment
     WHERE user_id=1 
    ORDER BY paym_date = (select MAX(paym_date) from user_payment and user_id=1);
    

    Or:

    SELECT MEMBSHIP_ID
    FROM (
      SELECT MEMBSHIP_ID, row_number() over (order by paym_date desc) rn
          FROM user_payment
         WHERE user_id=1 )
    WHERE rn = 1
    

提交回复
热议问题