select accnt_date,a.mem_code as mem_code,sum(case when b.deposit_type='01' then 1 else 0 end) as zdbzj_cs,
sum(case when b.deposit_type='01' and cur_accnt_code ='10' then net_amnt else 0 end ) as zdbaj_rmb,
sum(case when b.deposit_type='01' and cur_accnt_code ='14' then net_amnt else 0 end ) as zdbaj_my,
sum(case when b.deposit_type='02' and trade_sum>0 then 1 else 0 end) as bdbzj_cs,
sum(case when b.deposit_type='02' and trade_sum>0 and cur_accnt_code ='10' then net_amnt else 0 end ) as bdbaj_rmb,
sum(case when b.deposit_type='02' and trade_sum>0 and cur_accnt_code ='14' then net_amnt else 0 end ) as bdbaj_my,
sum(case when b.deposit_type='02' and trade_sum_2>0 then 1 else 0 end) as cebdbzj_cs,
sum(case when b.deposit_type='02' and trade_sum_2>0 and cur_accnt_code ='10' then net_amnt else 0 end ) as cebdbaj_rmb,
sum(case when b.deposit_type='02' and trade_sum_2>0 and cur_accnt_code ='14' then net_amnt else 0 end ) as cebdbaj_my
            from fx_dp_changebal a,fx_bzj_wlz b
where 
#where1#
and (a.next_usd_add<>0 or a.next_cny_add<>0)
and #where2#
and a.add_date = b.accnt_date and a.mem_code = b.mem_code
and b.sf_flag='1'
group by accnt_date,a.mem_code
order by accnt_date,a.mem_code请各位帮忙看下这个sql,在DB2中执行成功,但在程序中老是报a.mem_code上下文使用无效,这是哪门子的问题呀。谢谢。

解决方案 »

  1.   

    想在ORACLE中执行?
    #where1#
    #where2#
    是什么东东?在oracle中不能识别!
      

  2.   


    select accnt_date,
           a.mem_code as mem_code,
           sum(case
                 when b.deposit_type = '01' then
                  1
                 else
                  0
               end) as zdbzj_cs,
           sum(case
                 when b.deposit_type = '01' and cur_accnt_code = '10' then
                  net_amnt
                 else
                  0
               end) as zdbaj_rmb,
           sum(case
                 when b.deposit_type = '01' and cur_accnt_code = '14' then
                  net_amnt
                 else
                  0
               end) as zdbaj_my,
           sum(case
                 when b.deposit_type = '02' and trade_sum > 0 then
                  1
                 else
                  0
               end) as bdbzj_cs,
           sum(case
                 when b.deposit_type = '02' and trade_sum > 0 and
                      cur_accnt_code = '10' then
                  net_amnt
                 else
                  0
               end) as bdbaj_rmb,
           sum(case
                 when b.deposit_type = '02' and trade_sum > 0 and
                      cur_accnt_code = '14' then
                  net_amnt
                 else
                  0
               end) as bdbaj_my,
           sum(case
                 when b.deposit_type = '02' and trade_sum_2 > 0 then
                  1
                 else
                  0
               end) as cebdbzj_cs,
           sum(case
                 when b.deposit_type = '02' and trade_sum_2 > 0 and
                      cur_accnt_code = '10' then
                  net_amnt
                 else
                  0
               end) as cebdbaj_rmb,
           sum(case
                 when b.deposit_type = '02' and trade_sum_2 > 0 and
                      cur_accnt_code = '14' then
                  net_amnt
                 else
                  0
               end) as cebdbaj_my
      from fx_dp_changebal a, fx_bzj_wlz b
     where --#where1#
       (a.next_usd_add <> 0 or a.next_cny_add <> 0)
       --and #where2#
       and a.add_date = b.accnt_date
       and a.mem_code = b.mem_code
       and b.sf_flag = '1'
     group by accnt_date, a.mem_code
     order by accnt_date, a.mem_code
      

  3.   

    #where1# 是在jsp页面上接条件呀 不是这个问题的 它报a.mem_code上下文使用无效,但问题是在db2中执行可以的
      

  4.   

    a.mem_code上下文使用无效
    你看看 fx_dp_changebal 有mem_code这字段么?
      

  5.   

    accnt_date这个属性 是哪个表的。。前面加上别名 试试
      

  6.   

    最后面的group by 
    order by 的那个字段也标上  别名.字段
      

  7.   


    #where1#
      这个是什么意思你把语句里面的字段都加上所属表的别名
      

  8.   

    你的是到底是ORACLE 还是DB2