gpt4 book ai didi

mysql - 我从 select 进行的这次更新做错了什么

转载 作者:行者123 更新时间:2023-11-29 02:40:46 25 4
gpt4 key购买 nike

我一直在尝试从选择中进行更新,但控制台一直显示错误消息

您的 SQL 语法有误;查看与您的 MySQL 服务器版本对应的手册,了解在 'from 附近使用的正确语法 ( 选择 a.id_activity 作为统计 , a.date_reg 作为 l_clock ' 在第 5 行

我将不胜感激。

update user_stat set
clock_stat = a.stat
, datetime_lclock = a.l_clock
, date_fclock = a.f_clock
from
(
Select
a.id_activity as stat
, a.date_reg as l_clock
, date(c.date_reg) as f_clock
from log_activity a
inner join
(
select
max(id_reg) as last_Act,
min(id_reg) as first_Act
from log_activity
where uid = 1
)b on a.id_reg = b.last_Act
left join log_activity c on c.id_reg = b.first_Act
)a
where uid = 1;

最佳答案

你需要稍后设置值,所以一般的语法是这样的:

   UPDATE TABLEA a 
JOIN TABLEB b ON a.join_colA = b.join_colB
SET a.columnToUpdate = [something]

update user_stat
join
(
Select
a.id_activity as stat
, a.date_reg as l_clock
, date(c.date_reg) as f_clock
from log_activity
) a
inner join
( select
max(id_reg) as last_Act,
min(id_reg) as first_Act
from log_activity where uid = 1
)b on a.id_reg = b.last_Act
left join log_activity c on c.id_reg = b.first_Act
set
clock_stat = a.stat
, datetime_lclock = a.l_clock
, date_fclock = a.f_clock

关于mysql - 我从 select 进行的这次更新做错了什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52620610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com