update statement using nested query

后端 未结 6 1805
梦谈多话
梦谈多话 2020-12-14 06:33

I have a table:

mytable:
    id
    userID
    logDate
    lastLogDate

For every row in that table, I want to update the \'lastLogDate\' co

6条回答
  •  情深已故
    2020-12-14 07:06

    You can do this:

    UPDATE t
    SET t.logDate = t2.LatestDate
    FROM YourTable t
    INNER JOIN
    (
        SELECT userID, MAX(LogDate) LatestDate
        FROM YourTable
        GROUP BY userID
    ) t2 ON t.userID = t2.userID; 
    

提交回复
热议问题