select sum(money_fid) money,no from 
      (select * from t1
       union 
       select * from t2 ) group by no;

解决方案 »

  1.   

    感叹现在的开发人员之sql水平低下
      

  2.   

    one table, not 2 tables.
      

  3.   

    如果是一个表就是下面的语句:房东方佣金:price1 
    房东方员工编号:cust1
    房客方佣金:price2
    房客方员工编号:cust2
    select c.cust1,sum(c.price3+d.price4)  from (
    select sum(price1) price3,cust1 from tmp_ysj2 
    group by cust1) c,
    (select sum(price2) price4,cust2 from tmp_ysj2 
    group by cust2) d
    where c.cust1=d.cust2
    group by c.cust1
      

  4.   

    lou shang
    inner join is wrong, what if d has a cust2 which not presents in c, then you already kick off some rows.