select d.*
from a join b on a.id_i=b.id_i
     join c on b.id_c=c.id_c
     join d on c.zid_c=d.zid_c
where mc_c='一' and kc_i<=0

解决方案 »

  1.   

    select c.zid_c,d.kc_i
    from 表1 a inner join 表2 b on a.id_i=b.id_i
    left join 表3 c on b.id_c=c.id_c
    left join 表4 d on c.zid_c=d.zid_c
    where a.mc_c='一'
      

  2.   

    create table ta(id_i varchar(10),mc_c varchar(10))
    Insert into ta
    select '0001','一'
    union all select '0002','二'
    union all select '0003','三'create table tb(id_c varchar(10),id_i varchar(10))
    Insert into tb 
    select 'I0001','0001'
    union all select 'I0002','0001'
    union all select 'I0003','0002'create table tc(id_c varchar(10),zid_c numeric(10))
    Insert into tc 
    select 'I0001','147'
    union all select 'I0001','258'
    union all select 'I0002','147'
    union all select 'I0002','789'
    union all select 'I0003','589'create table td(zid_c numeric(10),kc_i varchar(10))
    Insert into td
    select 147,0
    union all select 147,-10
    union all select 258,20
    union all select 258,-20
    union all select 789,300
    union all select 789,-30select * from ta
    select * from tb
    select * from tc
    select * from td--刪除表
    drop table ta
    drop table tb
    drop table tc
    drop table tdselect distinct a2.zid_c,d.kc_i from 
    (select c.zid_c,a1.mc_c from
    (select b.id_c,a.mc_c from ta a inner join tb b on a.id_i=b.id_i)a1
    left join tc c on a1.id_c=c.id_c)a2
    left join td d on a2.zid_c=d.zid_c
    where a2.mc_c='一' and d.kc_i<=0--結果
    zid_c    kc_i
    --------------
    147 0
    147 -10
    258 -20
    789 -30
      

  3.   

    四个表名为tt1,tt2,tt3,tt4SELECT DISTINCT tt4.zid_c, tt4.kc_i
    FROM tt1 LEFT OUTER JOIN
          tt2 ON tt1.id_i = tt2.id_i LEFT OUTER JOIN
          tt3 ON tt2.id_c = tt3.id_c LEFT OUTER JOIN
          tt4 ON tt3.zid_c = tt4.zid_c
    WHERE (tt1.mc_c = '一') AND (tt4.kc_i <= 0)