sql - Update datetime column by one minute for few rows having same datetime -
i have table lots of data:
+----+-------+-------------------------+ | id | user | datetime | +----+-------+-------------------------+ | 1 | 34534 | 2015-08-12 10:03:22.043 | | 2 | 32423 | 2015-08-12 03:29:18.097 | | 3 | 12312 | 2015-08-13 03:24:10.073 | | 4 | 34232 | 2015-08-13 03:24:10.073 | | 5 | 32462 | 2015-08-13 03:24:10.073 | | 6 | 45354 | 2015-08-14 04:12:04.023 | +----+-------+-------------------------+
i want create 1 minute gap between datetime of rows same. in above case, row number 3,4,5. 1 minute gap in these 3 datetime.
try this
select id, user, [datetime] = case when rn = 1 [datetime] else dateadd(minute,rn-1,[datetime]) end ( select row_number()over(partition [datetime] order id) rn,* yourtable )
for updating table use this
with cte ( select row_number()over(partition [datetime] order id) rn,* yourtable ) update cte set [datetime] = case when rn = 1 [datetime] else dateadd(minute,rn-1,[datetime]) end
Comments
Post a Comment