日期:2014-05-17 浏览次数:21056 次
select a.id,a.name,sum(b.name) ,a.flag from a,b where a.id=b.id group by a.id,a.name,a.flag
------解决方案--------------------
select a.id,a.name,b1.sm,c1.sf from a left join (select id,sum(money) sm from b group by id) b1 on b1.id=a.id left join (select id,decode(sum(flag),0,0,1) sf from c group by id) c1 on c1.id=a.id
------解决方案--------------------
TRY IT ..
SQL> SELECT A.ID,
2 A.NAME,
3 SUM(DISTINCT MONEY) "SUM_MONEY",
4 MAX(FLAG) "FLAG"
5 FROM A,
6 B,
7 C
8 WHERE A.ID = B.ID
9 AND B.ID = C.ID
10 GROUP BY A.ID,A.NAME
11 ;
ID NAME SUM_MONEY FLAG
---------- ---- ---------- ----------
1 AA 80 1
2 BB 300 0
SQL>