select a.bmb02 seq,a.bmb03 partsno
,a.bmb06 mstdqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=a.bmb03 and t.ccs02='1112'),0) mstdcost
,0 stdsum
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=a.bmb01 and s.sfe07=a.bmb03),0) mfactqpa
,decode(nvl(b.bmb03,''),''
,nvl((select t.ccs03a from ccs_file t where t.ccs01=a.bmb03 and t.ccs02='1112'),0)
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.bmb03 and t.ccs02='1112'),0)*nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.bmb01 and s.sfe07=b.bmb03),0)
) mfactcost
,0 factsum
,b.bmb03 partno,b.bmb06 pstdqpa
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.bmb01 and s.sfe07=b.bmb03),0) pfactqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.bmb03 and t.ccs02='1112'),0) pcost
from bmb_file a,outer (bmb_file b)
where a.bmb03=b.bmb01
and a.bmb01='b11i12600a-zt01'
and a.bmb03 not in('b11i12600a-zt02','b11i12600a-zt01')--含本階層五金件
select a.ccn03 seq,a.ccn04 partsno
,a.ccn05 mstdqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=a.ccn04 and t.ccs02='1112'),0) mstdcost
,0 stdsum
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=a.ccn01 and s.sfe07=a.ccn04),0) mfactqpa
,decode(nvl(b.ccn04,''),''
,nvl((select t.ccs03a from ccs_file t where t.ccs01=a.ccn04 and t.ccs02='1112'),0)
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.ccn04 and t.ccs02='1112'),0)*nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.ccn01 and s.sfe07=b.ccn04),0)
) mfactcost
,0 factsum
,b.ccn04 partno,b.ccn05 pstdqpa
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.ccn01 and s.sfe07=b.ccn04),0) pfactqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.ccn04 and t.ccs02='1112'),0) pcost
from ccn_file a,outer (ccn_file b)
where a.ccn04=b.ccn01 and a.ccn02='1112' and b.ccn02='1112'
and a.ccn01='b11i12600a-zt01'
and a.ccn04 not in('b11i12600a-zt02','b11i12600a-zt01')
order by a.ccn04
--不含本階層五金件
select a.ccn03 seq,a.ccn04 partsno
,a.ccn05 mstdqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=a.ccn04 and t.ccs02='1112'),0) mstdcost
,0 stdsum
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=a.ccn01 and s.sfe07=a.ccn04),0) mfactqpa
,decode(nvl(b.ccn04,''),'',0
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.ccn04 and t.ccs02='1112'),0)*nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.ccn01 and s.sfe07=b.ccn04),0)
) mfactcost
,0 factsum
,b.ccn04 partno,b.ccn05 pstdqpa
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.ccn01 and s.sfe07=b.ccn04),0) pfactqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.ccn04 and t.ccs02='1112'),0) pcost
from ccn_file a,outer (ccn_file b)
where a.ccn04=b.ccn01 and a.ccn02='1112' and b.ccn02='1112'
and a.ccn01='b11i12600a-zt01'
and a.ccn04 not in('b11i12600a-zt02','b11i12600a-zt01')
--成功sql
select a.ccn03 seq,a.ccn04 partsno
,a.ccn05 mstdqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=a.ccn04 and t.ccs02='1112'),0) mstdcost
,0 stdsum
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=a.ccn01 and s.sfe07=a.ccn04),0) mfactqpa
,decode(nvl(b.ccn04,''),''
,nvl((select t.ccs03a from ccs_file t where t.ccs01=a.ccn04 and t.ccs02='1112'),0)
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.ccn04 and t.ccs02='1112'),0)*nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.ccn01 and s.sfe07=b.ccn04),0)
) mfactcost
,0 factsum
,b.ccn04 partno,b.ccn05 pstdqpa
,nvl((select sum(sfe16) from sfe_file s,sfb_file t where s.sfe01=t.sfb01 and t.sfb05=b.ccn01 and s.sfe07=b.ccn04),0) pfactqpa
,nvl((select t.ccs03a from ccs_file t where t.ccs01=b.ccn04 and t.ccs02='1112'),0) pcost
from ccn_file a,outer (ccn_file b)
where a.ccn04=b.ccn01 and a.ccn02='1112' and b.ccn02='1112'
and a.ccn01='b11i12600a-zt03'
and a.ccn04 not in('b11i12600a-zt01','b11i12600a-zt02')
order by a.ccn04
mysql資料庫查詢成本 Mysql查詢成本
理解了索引的原理,我們先來看一下單錶的查詢。表結構如下 create table single table id int not null auto increment,key1 varchar 100 key2 int,key3 varchar 100 key part1 varchar 100 ...
sql查詢慢 查詢
select creation time n 語句編譯時間 last execution time n 上次執行時間 total physical reads n 物理讀取總次數 total logical reads execution count n 每次邏輯讀次數 total logical ...
sql鑲嵌查詢 SQL 查詢巢狀使用
示例表如下 create table it student id int primary key auto increment,主鍵id name varchar 20 姓名 gender enum male female 性別 class id tinyint unsigned,班級號 age i...