寻找一个高效的SQL 联合查询方法
寻找一个高效的SQL 联合查询方法
现在代码如下,查询速度很慢,寻找高手看看有没有更好的办法
select * from (select w.che_no,h.kehu_no,w.kehu_mc,w.kehu_xm,k.kehu_tianjiagongsi,k.kehu_dh,h.jiesuan_rq,h.huifang_rq,w.kehu_dz,w.Xche_wxfl,w.che_cx,w.GongSiNo,w.kehu_dp,w.xche_jb,w.work_no from work_huifang_tix h inner join work_pz_sj w on h.work_no=w.work_no inner join kehu k on k.kehu_no=h.kehu_no where h.huifang_xz=0 )a left join (select work_huif_rq,kehu_no as che_number from work_huifang where id in (select max(id) from work_huifang group by kehu_no))b on a.kehu_no = b.che_number where 1=1 and ( 1<0 or GongSiNo='01' or GongSiNo='02') and huifang_rq>= '2014-1-7' and huifang_rq <'2014-1-15'
select *
from (
select w.che_no,h.kehu_no,w.kehu_mc,w.kehu_xm,k.kehu_tianjiagongsi,k.kehu_dh,h.jiesuan_rq,h.huifang_rq,w.kehu_dz,w.Xche_wxfl,w.che_cx,w.GongSiNo,w.kehu_dp,w.xche_jb,w.work_no
from work_huifang_tix h
inner join work_pz_sj w on h.work_no=w.work_no
inner join kehu k on k.kehu_no=h.kehu_no
where h.huifang_xz=0
)a
left join
(
select work_huif_rq,kehu_no as che_number
from work_huifang a
inner join
(
select max(id) id
from work_huifang
group by kehu_no
)b
on a.id = b.id
)b on a.kehu_no = b.che_number
where 1=1 and ( 1<0 or GongSiNo='01' or GongSiNo='02')
and huifang_rq>= '2014-1-7' and huifang_rq <'2014-1-15'