How to select records from last 24 hours using SQL?

后端 未结 11 2129
Happy的楠姐
Happy的楠姐 2020-12-04 04:41

I am looking for a where clause that can be used to retrieve records for the last 24 hours?

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-04 05:26

    In Oracle (For last 24 hours):

    SELECT  *
    FROM    my_table
    WHERE   date_column >= SYSDATE - 24/24
    

    In case, for any reason, you have rows with future dates, you can use between, like this:

    SELECT  *
    FROM    my_table
    WHERE   date_column BETWEEN (SYSDATE - 24/24) AND SYSDATE
    

提交回复
热议问题