1. 程式人生 > >關聯查詢 -單行子查詢返回多列

關聯查詢 -單行子查詢返回多列

例1:select * from table1 where id =(select id from table1);

由於子查詢結果中有多行,但是where條件id = 只能有一行記錄

例2: select (select name from emp where a.job = b.job) from emp

由於 子查詢的結果是多列 但是select 應該選擇 其中一列

 

 

 

關聯查詢:

select  w.id,r.id,w.appno,w.sgappno,bb.handle_context,

--單純需要把數字程式碼轉換成漢字,需要翻譯表時w.orgno = orgcode 找出對應的資料字典

(select orgname from org_orgnization where orgcode = w.orgno) orgname

from s_wkst w, bb

where w.appno = bb.appno

and tochar(w.handle_time,'yyyy-mm-dd') >='2018-08-01'

and tochar(w.handle_time,'yyyy-mm-dd') <='2018-08-30'

and w.orgno like '41404' || '%'