-2
我的兩個查詢單獨工作速度快,但是當我加入這兩個查詢花費的時間來執行很多,我的查詢被連接時速度很慢,分開他們快速
SELECT b.*,
a.*
FROM (SELECT r.vou_no,
r.vou_date,
r.lr_date,
r.due_date,
r.vac_code,
r.vamount,
r.vmfg_amt,
r.vter_cd,
r.mkt_year,
r.mnth_code
FROM ledfile AS r
WHERE r.mkt_year = 2012
AND r.mnth_code BETWEEN 201210 AND 201306
AND r.div_code = 1
AND r.vdepo_code = 21
AND r.vbook_cd = 80
AND Ifnull(r.del_tag, '') <> 'D'
ORDER BY r.vac_code,
r.vou_date,
r.vou_no) b,
(SELECT a.vac_code vcode,
a.vouno,
a.bill_date,
a.vamount vamt,
a.vou_date vdate
FROM rcpfile a
WHERE a.mkt_year = 2012
AND a.div_code = 1
AND a.vdepo_code = 21
AND a.vbook_cd IN (20, 21, 22, 90,
98, 80)
AND Ifnull(a.del_tag, '') <> 'D'
ORDER BY a.vac_code,
a.bill_date,
a.vouno) a
WHERE a.vcode = b.vac_code
AND a.vouno = b.vou_no
AND a.bill_date = b.vou_date;
可以請您分開部分 –
說明你在做什麼,不要只是放在牆上的代碼。請正確格式化。 – Pablo
要在多個表上的查詢中執行更快的JOIN,在表上具有適當的索引非常重要。在查詢中加入的列必須位於索引中。 – DOK