SQL 如何选择最近的日期项

2021-12-19 00:00:00 sql date select oracle

你好,我有一个带列的表:

Hello I have a table with columns:

*使用oracle

ID                  NUMBER
USER_ID            NUMBER
DATE_ADDED          DATE
DATE_VIEWED        DATE
DOCUMENT_ID        VARCHAR2
URL                VARCHAR2
DOCUMENT_TITLE      VARCHAR2
DOCUMENT_DATE        DATE

我想知道如何获取给定用户最近添加的文档.

I want to know how i can get the most recently added document for a given user.

Select * FROM test_table WHERE user_id = value AND (do something with date_added column)

谢谢

推荐答案

Select * 
FROM test_table 
WHERE user_id = value 
AND date_added = (select max(date_added) 
   from test_table 
   where user_id = value)

相关文章