1)select t1.id  "识别号",t1.mc  "名称",sum(t2.ynse) 应纳税额,sum(t3.sjse) 实缴税额 sum(t2.ynse)-sum(t3.sjse) 欠税
from table1 t1 left join table2 t2 on t1.id=t2.id left join table3 t3 on t1.id=t3.id
where t2.sbrq='2003-11' and t3.kprq='2003-11'
group by id
2)select t1.id ,t2.*,t3.*
from table1 t1 left join table2 t2 on t1.id=t2.id left join table3 t3 on t1.id=t3.id

解决方案 »

  1.   

    select a.id,sum(ynse) 应纳税额,sum(sjse) 实缴税额 sum(ynse)-sum(sjse) 欠税
    from table1 a left outer join table2 b on a.id = b.id
    left join table3 c on a.id = b.id
    group by a.id
      

  2.   

    select a.id,sum(ynse) 应纳税额,sum(sjse) 实缴税额 sum(ynse)-sum(sjse) 欠税
    from table1 a left outer join table2 b on a.id = b.id
    left join table3 c on a.id = b.id
    where b.sbrq='2003-11' and c.kprq='2003-11'
    group by a.id
      

  3.   

    select a.id  "识别号",a.mc  "名称",sum(b.ynse) 应纳税额,sum(c.sjse) 实缴税额 sum(b.ynse)-sum(c.sjse) 欠税
    from table1 a,table2 b,table3 c where a.id=b.id(+) and a.id=c.id(+) and b.sbrq='2003-11' and c.kprq='2003-11'
    group by a.id
      

  4.   

    上述查询结果反映的实质只是table2/table3中都有的id数据,即纳税人(该id)即申报、又有交税。并没反应出只申报没交税的纳税人(table2中有数据,table3中无数据)或者未申报、却交税了的人。
      

  5.   

    应该是,如table2中有,取相应数,table3中无,取值0.如table3中有,取相应数,无,取“未申报“   请不要用临时表过渡!