日期:2014-05-17  浏览次数:20751 次

怎么样改,才能提高sql效率
SELECT *,
(select top 1 addtime from zu_job_money_detail where zu_job_money_detail.comid=zu_job_company.id and flag=1 order by intid desc)as md_zjjftime,
(select top 1 addtime from zu_job_money_detail where zu_job_money_detail.comid=zu_job_company.id and flag=1 order by intid asc)as md_dyckaitong,
(select top 1 validity from zu_job_money_detail where zu_job_money_detail.comid=zu_job_company.id and flag=1 order by intid desc)as md_vipendtime,
(select top 1 paytype from zu_job_money_detail where zu_job_money_detail.comid=zu_job_company.id and flag=1 order by intid desc) as md_paytype 
FROM zu_job_company order by id desc

------解决方案--------------------
探讨
今天没人吗?

------解决方案--------------------
SQL code

select a.*,
        c.addtime as md_zjjftime,
        d.addtime as md_dyckaitong,
        c.validity as md_vipendtime,
        c.paytype as md_paytype
from zu_job_company a
left join 
(
    select comid,MAX(intid) as maxid,MIN(intid) as minid from zu_job_money_detail
    where flag=1
    group by comid
) b  on a.id=b.comid
left join zu_job_money_detail c on b.maxid = c.id 
left join zu_job_money_detail d on b.minid = d.id

------解决方案--------------------
探讨

SQL code

select a.*,
c.addtime as md_zjjftime,
d.addtime as md_dyckaitong,
c.validity as md_vipendtime,
c.paytype as md_paytype
from zu_job_company a
left join
(
……