select a.svoucherno,a.setid,a.year,a.totalmoney,a.voudate,
a.eid,e.name ename,mid,m.name mname,a.bid,b.name bname,
a.iid,a.pid,p.name pname
from (select v.svoucherno,v.setid,v.year,v.totaldeb totalmoney,
v.year||'-'||substr('00'||v.month,length('00'||v.month)-1,2)||'-'||substr('00'||v.day,length('00'||v.day)-1,2) voudate,
(select substr(aid,4,length(aid)-2) from assistantvoudetail avd
where instr(aid,'003')=1
and v.svoucherno=avd.svoucherno and line=1) eid,
(select substr(aid,4,length(aid)-2) from assistantvoudetail avd
where instr(aid,'004')=1
and v.svoucherno=avd.svoucherno and line=1) mid,
(select substr(aid,4,length(aid)-2) from assistantvoudetail avd
where instr(aid,'005')=1
and v.svoucherno=avd.svoucherno and line=1) bid,
(select substr(aid,4,length(aid)-2) from assistantvoudetail avd
where instr(aid,'006')=1
and v.svoucherno=avd.svoucherno and line=1) iid,
(select substr(aid,4,length(aid)-2) from assistantvoudetail avd
where instr(aid,'007')=1
and v.svoucherno=avd.svoucherno and line=1) pid,
(select substr(aid,4,length(aid)-2) from assistantvoudetail avd
where instr(aid,'008')=1
and v.svoucherno=avd.svoucherno and line=1) did
from voucher v) a,enterprise e,budget_type_prop m,budgetsection b,payoffkind p
where a.eid = e.eid and a.year=e.year
and a.mid = substr(m.code,2,3)
and a.bid = b.bid and a.year=b.year
and a.pid = p.pid and a.year=p.year
红字部分是子查询,单独执行比较快。
但结果和其他表连接,由于子查询没法建索引,导致比较慢,如何解决呢?
能想出的办法是先建子查询的结果插入新建表A,建好索引,再将A表和其他表连接,结果很快。
还有其他办法吗?