2012-03-22 61 views
0

上午使用MySQL 5.5.9在Windows 7 32位家伙是真的很糟糕的情况需要绝望的帮助 在我的程序中我有临时表temp01 和在我的数据库我有代理表和我的存储过程有IN Ico_id int作为参数 与此一起,我没有在temp01表cl列请记下它。Mysql更新表与选择使用组

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'; 

当我运行存储过程把它给我的错误:在“上cluase”

回答

1

你的子查询只返回一列(cl)未知列tt.t_co_id。您将此子查询别名为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列,因为您接下来会看到该错误。 ;)