2017-05-24 16 views
-1

以下のSQLクエリをスピードアップする機会がありますか?あなたは 'order by xtrid desc' を取り出すことができるSQLの最適化(グループ別と最大)

select 
    max(xtrid) as xtrid 
    , jid 
from jpltab jl 
    inner join rb_cust u 
    on jl.custid = u.custid 
where jl.tpe = 'Y' 
    and jl.jid in (51, 52, 53, 54, 55) 
    and u.org = 'INVCE' 
group by jid 
order by xtrid desc; 

おかげ

+1

インデックスを追加.... –

+0

あなたは実行計画をしてください含めることができますか? – VDK

+0

'Where'句の' jl.jid'に連続する数字があるので、 'IN(51,52,53,54,55) 'の代わりに' 51と55の間'に変更してください。これにより、パフォーマンスが向上します。ここを参照してください... https://stackoverflow.com/questions/3308280/is-there-a-performance-difference-between-between-and-in-with-mysql-or-in-sql-in –

答えて

-3

すでに最大に

+0

各グループの最大値を選択しています... –

+0

はい...各グループの最大値を選択するには、値をグループ単位で並べる必要はありません。 – heyhey

1

を選択しているので、これはあなたのクエリです:

select jl.jid, max(xtrid) as xtrid 
from jpltab jl inner join 
    rb_cust u 
    on jl.custid = u.custid 
where jl.tpe = 'Y' and 
     jl.jid in (51, 52, 53, 54, 55) and 
     u.org = 'INVCE' 
group by jl.jid 
order by xtrid desc; 

私はインデックスを開始します。心に浮かぶのはjpltab(tpe, jid, custid)rb_cust(custid, org)です。