gpt4 book ai didi

mysql - 更新表嵌套查询(使用函数)

转载 作者:行者123 更新时间:2023-11-29 05:37:13 24 4
gpt4 key购买 nike

在我的查询中,我想更新表“tblUser_Report”的行。它有日期字段我只想更新具有最高日期值的行(我的意思是最近的日期)

但是我收到错误提示,您不能在“更新”中包含“来自”...还有其他方法吗?附言数据库:- MySQL

update tblUser_Report set Status='A',S_Date='"+date+"' 
where Employee_ID="+id+"
AND
S_Date=(select MAX(S_Date)
from tblUser_Report
where Employee_ID="+id+")";

最佳答案

使用 JOINed 子查询尝试此查询 -

UPDATE tblUser_Report t1
JOIN (SELECT MAX(S_Date) s_date
FROM
tblUser_Report
WHERE
Employee_ID = 1) t2
ON t1.s_date = t2.s_date
SET
t1.Status = 'A', t1.S_Date = DATE(NOW())
WHERE
t1.Employee_ID = 1

关于mysql - 更新表嵌套查询(使用函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9682988/

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