如: ide
表全部字段:背景色爲要取出的字段spa
unit表:num, bm, dw_name, dw_name_pre, dw_codecode
work表: name, do, check, isdel, writetime, qy_codeit
其中,unit表dw_code == work表qy_codeclass
查詢語句以下:date
select a.*, b.* from select
(im
select qy_code,數據
to_char(writetime, 'yyyymmdd') T,查詢
count(1) N
from work where qy_code like ('110110%')
and do = 9
and check = 9
and isdel = 0
and writetime > to_date('2019/09/3 23:59:59', 'yyyy/mm/dd hh24:mi:ss') group by qy_code, to_char(writetime, 'yyyymmdd')
) a left join (select dw_name, dw_name_pre , dw_code from unit ) b on a.qy_code=b.dw_code order by b.dw_name_pre, a.T asc
要取的數據是unit表的字段比較多,因此放到 left join的左邊。
work表要取的字段比較少,因此放到 letf join的右邊。
on後面接的是兩表關聯的字段。
最上邊的select a.*, b.* from 是將兩表中已提取出的字段所有顯示出來。