gpt4 book ai didi

Mysql 使用 group by 选择更新表

转载 作者:行者123 更新时间:2023-11-29 14:32:01 25 4
gpt4 key购买 nike

我在 windows 7 32 位上使用 mysql 5.5.9 伙计们,情况真的很糟糕,需要绝望的帮助在我的程序中,我有临时表 temp01在我的数据库中,我有代理表,我的存储过程有 IN Ico_id int 作为参数除此之外,我在 temp01 表中没有 cl 列,请记下它。

update agent a 
join (
select sum(ifnull(t_dr_amt,0)) - sum(ifnull(t_cr_amt,0)) as cl
from temp01
group by t_ac_id
) as tt
on a.co_id = tt.t_co_id
and a.agent_id = tt.t_ac_id
SET a.cl = tt.cl
where a.co_id = 1
AND lower(a.io) = 'y';

当我运行存储过程时,它给我错误:“on cluase”中的未知列 tt.t_co_id

最佳答案

您的子查询仅返回一列 (cl)。您将此子查询别名为 tt,因此没有 tt.t_co_id。如果这是 temp01 中的一列,您可以将其更改为:

select 
sum(ifnull(t_dr_amt,0)) - sum(ifnull(t_cr_amt,0)) as cl,
t_co_id,
t_ac_id
from temp01
group by t_ac_id

这样您也可以选择 t_co_id 列。我还添加了 t_ac_id 列,因为接下来您会在该列上收到错误。 ;)

关于Mysql 使用 group by 选择更新表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9824520/

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