各位大神,今天見到一個sql,如下,查詢t1.id有在與t2.id進行左聯結時的條數,發現運用了大量重復的左聯結,感覺很不好,但又不知道怎么修改這個sql,請指教: create table t1(id number);create table t2(id number,val varchar2(10));select a1.id,count(
各位大神,今天見到一個sql,如下,查詢t1.id有在與t2.id進行左聯結時的條數,發現運用了大量重復的左聯結,感覺很不好,但又不知道怎么修改這個sql,請指教:
create table t1(id number); create table t2(id number,val varchar2(10)); select a1.id,count(1) from t1 a1 left outer join t2 b1 on a1.id = b1.id and b1.val = 'a' left outer join t2 b2 on a1.id=b2.id and b2.val='b' left outer join t2 b2 on a1.id=b2.id and b2.val='c' left outer join t2 b2 on a1.id=b2.id and b2.val='d' left outer join t2 b2 on a1.id=b2.id and b2.val='e' group by a1.id;
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com