gpt4 book ai didi

mysql - 连接两个表并更新 MySql 中的第三个表

转载 作者:行者123 更新时间:2023-11-29 21:47:49 25 4
gpt4 key购买 nike

我正在尝试连接两个表tblN1tblN2来获取用户的总访问次数,并更新第三个表tblNCC,而无需成功,因为我有错误:

[Err] 1054 - Unknown column 't.UserN1' in 'on clause'

我不明白这个错误...列 t.UserN1 位于 Select sql 查询中。

也许问题出在 Union All 语法上?

我的代码如下,请帮助我。

提前非常感谢您。

UPDATE tblNCC AS CC
JOIN (
SELECT
sum(total) AS Total
FROM
(
SELECT
COUNT(*) AS Total,
UserN1
FROM
`tblN1`
WHERE
UserN1 IN ('7047505')
AND dateN1 BETWEEN MAKEDATE(YEAR(CURDATE()), 1)
AND CURDATE()
UNION ALL
SELECT
COUNT(*) AS Total,
UserN2
FROM
`tblN2`
WHERE
UserN2 ('7047505')
AND dateN2 BETWEEN MAKEDATE(YEAR(CURDATE()), 1)
AND CURDATE()
) AS t
) AS q ON t.UserN1 = CC.UserNcc
SET CC.Total = t.Total;
[Err] 1054 - Unknown column 't.UserN1' in 'on clause'

最佳答案

t 不在范围内。它在q里面。

你的意思可能是这样的:

UPDATE tblNCC AS CC
JOIN (
SELECT
username,
sum(total) AS Total
FROM
(
SELECT
COUNT(*) AS Total,
UserN1 as username
FROM
`tblN1`
WHERE
UserN1 IN ('7047505')
AND dateN1 BETWEEN MAKEDATE(YEAR(CURDATE()), 1)
AND CURDATE()
UNION ALL
SELECT
COUNT(*) AS Total,
UserN2 as username
FROM
`tblN2`
WHERE
UserN2 ('7047505')
AND dateN2 BETWEEN MAKEDATE(YEAR(CURDATE()), 1)
AND CURDATE()
) AS t
) AS q ON q.username = CC.UserNcc
SET CC.Total = q.Total;

关于mysql - 连接两个表并更新 MySql 中的第三个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33959673/

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