如果表1的zd1得值是唯一的,而表2的zd1有重复值
select a0.zd1,表1.zd2,a2.zd3 from (SELECT zd1 FROM 表1 UNION sele zd1 FROM 表2) a0 LEFT OUTER JOIN (select zd1,sum(zd2) as zd3 from 表2 group by zd1) a2 ON a2.zd1=a0.zd1 left outer join 表1 on 表1.zd1=a0.zd1
如果表1和表2的zd1都有重复值(建议使用)
select a0.zd1,a1.zd2,a2.zd3 from (SELECT zd1 FROM 表1 UNION sele zd1 FROM 表2) a0 LEFT OUTER JOIN (select zd1,sum(zd2) zd3 from 表2 group by zd1) a2 ON a2.zd1=a0.zd1 left outer join (select zd1,sum(zd2) zd2 from 表1 group by zd1) a1 on a1.zd1=a0.zd1
以上代码是参考4楼修改的。
[
本帖最后由 sywzs 于 2010-3-9 07:03 编辑 ]