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_paytypefrom zu_job_company aleft 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.comidleft join zu_job_money_detail c on b.maxid = c.id left join zu_job_money_detail d on b.minid = d.id
------解决方案--------------------