如何在sql中获取最近3个小时的更新记录

时间:2021-11-27 10:19:21

I have a table Employee. Somebody has updated a few records in the last 3 hrs. I want to get those record which were updated. If possible, I want the diff between the previous and current record in sql. I'd like an answer as a query.

我有一张桌子员工。有人在过去3小时内更新了一些记录。我想得到那些更新的记录。如果可能的话,我想在sql中的先前和当前记录之间进行差异。我想要一个答案作为查询。

2 个解决方案

#1


3  

Use DATEDIFF:

SELECT e.*
FROM Employee e
WHERE DATEDIFF(HOUR, e.UpdatedAt, GETDATE()) <= 3

#2


0  

If you have any columns in the table with datatype Row version, then a timestamp value will be added automatically to each rows in your table. This column value will be modified at each time any operation performed on the particular row.Row Version is the Timestamp value for the rows.TIMESTAMP value of row(s) would be automatically updated if we UPDATE any value of row(s) in the table. New TIMESTAMP value will always be the next incremented value of the largest TIMESTAMP value exist among all rows in the table.To get the last updated , just query the latest 3 row version columns

如果表中的任何列的数据类型为Row version,则时间戳值将自动添加到表中的每一行。每次在特定行上执行任何操作时,都会修改此列值。如果我们更新行中的任何行,则行的行的时间戳值将自动更新行的时间戳值。表。新的TIMESTAMP值将始终是表中所有行中存在的最大TIMESTAMP值的下一个递增值。要获取上次更新,只需查询最新的3行版本列

CREATE TABLE Employee(EmployeeID int PRIMARY KEY, VerCol rowversion) ;

#1


3  

Use DATEDIFF:

SELECT e.*
FROM Employee e
WHERE DATEDIFF(HOUR, e.UpdatedAt, GETDATE()) <= 3

#2


0  

If you have any columns in the table with datatype Row version, then a timestamp value will be added automatically to each rows in your table. This column value will be modified at each time any operation performed on the particular row.Row Version is the Timestamp value for the rows.TIMESTAMP value of row(s) would be automatically updated if we UPDATE any value of row(s) in the table. New TIMESTAMP value will always be the next incremented value of the largest TIMESTAMP value exist among all rows in the table.To get the last updated , just query the latest 3 row version columns

如果表中的任何列的数据类型为Row version,则时间戳值将自动添加到表中的每一行。每次在特定行上执行任何操作时,都会修改此列值。如果我们更新行中的任何行,则行的行的时间戳值将自动更新行的时间戳值。表。新的TIMESTAMP值将始终是表中所有行中存在的最大TIMESTAMP值的下一个递增值。要获取上次更新,只需查询最新的3行版本列

CREATE TABLE Employee(EmployeeID int PRIMARY KEY, VerCol rowversion) ;