select 語法
我有一個select 語法如下,
查詢的速度相當慢,
table prd20資料約一萬多筆,
table sto14資料約一千萬筆,
請問我的語法有問題嗎?
還是我該如何修改能加快查詢速度?感謝!
select prd2001,prd2002
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'A'
group by prd2001,prd2002) ,0) A
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'B'
group by prd2001,prd2002) ,0) B
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'C'
group by prd2001,prd2002) ,0) C
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'D'
group by prd2001,prd2002) ,0) D
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'E'
group by prd2001,prd2002) ,0) E
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'F'
group by prd2001,prd2002) ,0) F
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'G'
group by prd2001,prd2002) ,0) G
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'H'
group by prd2001,prd2002) ,0) H
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'I'
group by prd2001,prd2002) ,0) I
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'J'
group by prd2001,prd2002) ,0) J
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'K'
group by prd2001,prd2002) ,0) K
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'L'
group by prd2001,prd2002) ,0) L
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'M'
group by prd2001,prd2002) ,0) M
,nvl((select sum(sto1410)
from sto14
where sto1404 = prd2001
and sto1405 = prd2002
and sto1406 = 'U'
group by prd2001,prd2002) ,0) U
from prd20
where prd2006='12'
and prd2007 = '3'
and prd2008 = '1'
order by prd2001,prd2002;