update statement using nested query

后端 未结 6 1775
梦谈多话
梦谈多话 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:18

    UPDATE mytable mT,
      (SELECT userid,
              MAX(logDate) AS maxDateForUser
       FROM mytable
       GROUP BY userId) t
    SET mT.lastLogDate = t.maxDateForUser
    WHERE mT.userid = t.userid;
    

提交回复
热议问题