gpt4 book ai didi

mysql - 如何使用内连接更新选择中的字段值?

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

我正在尝试使用带有内部联接的选择查询来更新 mysql 数据库中的字段值

我目前得到

1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 5 行“AS cc WHERE cc.account_id = na.account_id”附近使用的正确语法

UPDATE accounts AS na
SET na.pdm_id = (
SELECT cp.person_id FROM `temp_accounts` AS ta INNER JOIN call_managment_system.accounts AS a ON ta.company_code = a.company_code
INNER JOIN contact_personal AS cp ON cp.name = ta.FSM AND contact_link = 'PDM'
)
WHERE a.account_id = na.account_id

如何修复此查询以使其正常工作?我想更新名为 pdm_id 的字段,将其设置为等于 cp.person_id

谢谢

最佳答案

UPDATE  accounts na
INNER JOIN call_managment_system.accounts a
ON a.account_id = na.account_id
INNER JOIN temp_accounts ta
ON ta.company_code = a.company_code
INNER JOIN contact_personal cp
ON cp.name = ta.FSM
SET na.pdm_id = cp.person_id
WHERE contact_link = 'PDM'

关于mysql - 如何使用内连接更新选择中的字段值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16049845/

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