I am using SQL Server 2019. I have a table in my database which contains a column called update_date. For example, if I have the following data, I would like to import one data per hour within the last 24 hours.
2023-11-28 14:50:55
2023-11-28 15:10:33
2023-11-28 15:11:33
2023-11-28 15:53:33
2023-11-28 16:13:35
2023-11-28 16:56:49
2023-11-28 16:56:50
2023-11-29 00:37:02
2023-11-29 00:40:02
2023-11-29 00:41:02
2023-11-29 00:42:02
2023-11-29 00:44:02
I would like to return
2023-11-28 14:50:55
2023-11-28 15:10:33
2023-11-28 16:13:35
2023-11-29 00:37:02
SELECT *
FROM table
WHERE update_date >= DATEADD(HOUR , -24, GETDATE())
I don't know how to add a query. Please help me
1条答案
按热度按时间gcmastyq1#
You can do it using
GROUP BY
andMIN()
: