我们如何在mysql中运行这些类型的查询?
一个人帮我执行这些类型的查询我们如何在mysql中运行。更新连接查询
UPDATE file_master t1,users t2 SET
t1.Status = "cancel",
t1.is_credit_revers=1,
t1.is_credit_reversed=1,
t1.t_reversal=t1.credit,
t2.credit=t1.credit+
(
select sum(t1.credit) from file_master where FileID in(7,6,5)
)
WHERE t1.FileID in(7,6,5)
and t1.CRN=t2.id
and t1.CRN=1 ;
1093 - 表' t1'被指定两次,两者都作为'更新'的目标。并作为数据的单独来源
答案 0 :(得分:1)
MySQL对象更新也在子查询中的表
您有时可以在另一个子查询中隐藏子查询以解决此问题。
因此尝试这样的事情: -
UPDATE file_master t1
INNER JOIN users t2
ON t1.CRN = t2.id
CROSS JOIN
(
SELECT credit_sum
FROM
(
SELECT SUM(credit) AS credit_sum
FROM file_master
WHERE FileID IN(7,6,5)
) t3
) t4
SET t1.Status = "cancel",
t1.is_credit_revers = 1,
t1.is_credit_reversed = 1,
t1.t_reversal = t1.credit,
t2.credit = t1.credit + t4.credit_sum
WHERE t1.FileID in(7,6,5)
AND t1.CRN = 1 ;