DB2效率查询对比



select app.app_NO, app.TRANSFER_ORGAN,app.STATE, t.BACK_DATE,t.FEEDBACK_DATE,t.RECEIVE_DATE,t.RETURN_DATE,Db_num,daly_num
from App_register app 
left join (
select a.app_no, a.BACK_DATE,a.FEEDBACK_DATE,a.RECEIVE_DATE,a.RETURN_DATE,Db_num,daly_num
from TURN_INFO a 
left join (
select turn_id,count(SUPERVISE_DELAY_INFO.DELAY_REASON)as daly_num,count(SUPERVISE_DELAY_INFO.SUPERVISE_OPINION)as Db_num
from  DB2INST2.SUPERVISE_DELAY_INFO
group by turn_id
) b
on a.ID=b.turn_id
) t
on app.APP_NO= t.APP_NO
where app.APP_NO_ZJ='2c909e0f57a203220157a20508aa0001'

将条件放到里面去会提高查询效率:上面0.003s 下面 0.002

select a2.app_NO_zj,a2.app_no, a2.TRANSFER_ORGAN,a2.STATE, a2.BACK_DATE,a2.FEEDBACK_DATE,a2.RECEIVE_DATE,a2.RETURN_DATE,count(a1.DELAY_REASON)as daly_num,count(a1.SUPERVISE_OPINION) from
(
select app.app_NO_zj,app.app_no, app.TRANSFER_ORGAN,app.STATE,t.id, t.BACK_DATE,t.FEEDBACK_DATE,t.RECEIVE_DATE,t.RETURN_DATE
from app_register as app join turn_info as t on app.app_no=t.app_no
where app.APP_NO_ZJ ='2c909e0f57a203220157a20508aa0001'
) a2
left join 
supervise_delay_info as a1  on a2.id = a1.turn_id
group by a2.app_NO_zj,a2.app_no, a2.TRANSFER_ORGAN,a2.STATE, a2.BACK_DATE,a2.FEEDBACK_DATE,a2.RECEIVE_DATE,a2.RETURN_DATE



你可能感兴趣的:(SQL)