日期:2014-05-18 浏览次数:20743 次
select newcode,iname,max(iiname),max(iiiname) from (select t1.newcode,iname,iiname,iiiname from table1 t1,table2 t2,table3 t3 where t1.newcode=t2.newcode and t1.newcode=t3.newcode) t group by newcode,iname; select newcode,iname,min(iiname),min(iiiname) from (select t1.newcode,iname,iiname,iiiname from table1 t1,table2 t2,table3 t3 where t1.newcode=t2.newcode and t1.newcode=t3.newcode) t group by newcode,iname;
------解决方案--------------------
select t1.newcode, t1.iname, t2.iiname, t3.iiiname from table1 t1 join (select newcode, min(iiname) from table2 group by newcode) t2 on t1.newcode=t2.newcode join (select newcode, min(iiiname) from table3 group by newcode) t3 on t1.newcode=t3.newcode