dsfo22654 2014-09-27 16:24
浏览 162

如何更新超过30秒或30分钟的行[重复]

This question already has an answer here:

I'm trying to figure out how to update MySQL rows older than 30 seconds or 30 minutes.

$sql = "SELECT C.sessid, C.datetime, U.username, U.firstname, U.lastname, U.sessid FROM checkins C, users U WHERE U.sessid = C.sessid AND SUBTIME(NOW(),'0 00:01:00')>C.datetime";
$result = mysql_query( $sql );
while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
mysql_query("UPDATE checkins SET status = 'was in'");
}

Here I have joined tables, just the users table and checkins table. I am using subtime to determine the time difference and trying to update rows of checkins table if the C.datetime is older than 1 minute just for a test

</div>
  • 写回答

1条回答 默认 最新

  • dt4320279 2014-09-27 16:29
    关注

    Is this what you are looking for?

    UPDATE checkins c join
           users u
           on c.sessid = u.sessid
        SET status = 'was in'
        WHERE c.datetime < now() - interval 30 second;
    

    The users table is probably not needed, unless you require it for filtering.

    Just change the 30 second to 30 minute for a 30 minute interval.

    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)