select A.c_A1,A.c_A2,B.c_B2,
isnull(sum(case when n_bz=2 then C.n_je end),0) as n_1,
isnull(sum(case when n_bz=3 and YEAR(d_rq)='2006' then C.n_je end),0) as n_2,
isnull(sum(case when n_bz=0 then C.n_je end),0) as n_3,
isnull(sum(case when n_bz=1 then C.n_je end),0) as n_4 
from C,B,D LEFT OUTER JOIN A where C.c_B1=B.c_B1 and 
C.c_D=D.c_D and C.c_A=A.c_A
 and C.d_rq>='2006.01.01' and C.d_rq<='2006.07.12' and C.c_B1='02' and C.c_D='02'
 group by A.c_A,A.c_A2,B.c_B2 order by A.c_A2总提示
在关键字 'where' 附近有语法错误。
不知道该怎样写?

解决方案 »

  1.   

    select A.c_A1,A.c_A2,B.c_B2,
    isnull(sum(case when n_bz=2 then C.n_je end),0) as n_1,
    isnull(sum(case when n_bz=3 and YEAR(d_rq)='2006' then C.n_je end),0) as n_2,
    isnull(sum(case when n_bz=0 then C.n_je end),0) as n_3,
    isnull(sum(case when n_bz=1 then C.n_je end),0) as n_4 
    from C inner join B on C.c_B1=B.c_B1
    inner join D on C.c_D=D.c_D
    LEFT OUTER JOIN A on  C.c_A=A.c_A
    where C.d_rq>='2006.01.01' and C.d_rq<='2006.07.12' and C.c_B1='02' and C.c_D='02'
     group by A.c_A,A.c_A2,B.c_B2 order by A.c_A2
      

  2.   

    Join 是用在 From 里面的,当然要在 where 之前
    但 Join 的链接条件用的是 on 而不是在where中写的
      

  3.   

    LEFT OUTER JOIN需要指定连接条件.即要ON 关健字指定连接条件.CROSS JOIN 是交叉所以不用.