[英]Save mysql query result into same database table
Trying to calculate the time difference between current time and the user's settime to get results in minutes and it works, but is there a way to save the same result into table column on the latest row? 试图计算当前时间与用户设置时间之间的时差,以分钟为单位获取结果,并且可以,但是有没有办法将相同结果保存到最新行的表列中?
SELECT settime, TIMESTAMPDIFF(MINUTE,CURRENT_TIMESTAMP(), settime)AS timeleft
FROM feedtime
On the left side image, it shows result "timeleft" correctly but also an error Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
在左侧图像中,它正确显示了结果“ timeleft”,但也出现了错误。 Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
Where as my id column is already set as primary, unique and auto_increment 我的id列已设置为primary,unique和auto_increment
Is there a way i could take the result and update into right side image shown column as timeleft? 有没有一种方法可以获取结果并更新为显示为timeleft的右侧图像?
Yes, use an UPDATE
statement: 是的,使用UPDATE
语句:
UPDATE feedtime
SET timeleft = TIMESTAMPDIFF(MINUTE, CURRENT_TIMESTAMP(), settime);
Note that MySQL may insist that you add a WHERE
clause which uses a condition on the id
column, eg 请注意,MySQL可能会坚持要求您添加一个在id
列上使用条件的WHERE
子句,例如
UPDATE feedtime
SET timeleft = TIMESTAMPDIFF(MINUTE, CURRENT_TIMESTAMP(), settime)
WHERE id = 1;
Even if MySQL does not require this, you still might want to add a WHERE
clause to limit the scope of the update. 即使MySQL不需要这样做,您仍然可能想要添加WHERE
子句以限制更新范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.