如果是一个表就是下面的语句:房东方佣金: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
lou shang inner join is wrong, what if d has a cust2 which not presents in c, then you already kick off some rows.
房东方员工编号: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
inner join is wrong, what if d has a cust2 which not presents in c, then you already kick off some rows.