日期:2014-05-17 浏览次数:20791 次
SQL> select * from t1;
ID YJLX YJCONTENT CREATE_DAT YJSOURCE
---------- ---- ---------- ---------- ----------
1 good 123 2012-04-08 1
2 mid 123 2012-04-08 2
3 bad 123 2012-04-08 3
SQL> select * from t2;
ID PID CUS_ CREATE_DAT
---------- ---------- ---- ----------
1 1 z1 2012-04-08
1 2 z2 2012-04-08
2 3 z3 2012-04-08
2 4 z4 2012-04-08
2 5 z5 2012-04-08
SQL> select t1.id,t1.yjlx,nvl(t.count,0),t1.create_date,t1.yjsource from (select id,count(id) count from t2 group by id) t right join t1 on t.id = t1.id;
ID YJLX NVL(T.COUNT,0) CREATE_DAT YJSOURCE
---------- ---- -------------- ---------- ----------
1 good 2 2012-04-08 1
2 mid 3 2012-04-08 2
3 bad 0 2012-04-08 3
SQL>