业务表LGLK_QXDTB Fwqbh 有多条记录,只需要改字段最新的一条记录。
sql如下
select * from (select q.Fcrfs, Fmjsj, '' Fdate, '' Ftime,LGLK_RECORDS.FmemberName,q.Fbmmc,
a.ssdwmc, a.wqmc,a.wqlx,a.qh,dbo.GET_SJBM_BYID(q.fsjbmbm,'2') AS SJBM2 ,
q.Fdate AS CloseDate,
q.Ftime AS CloseTime , a.syrxm,q.fsjbmbm ,q.sqdh ,ROW_NUMBER() OVER ( PARTITION BY Fwqbh order by q.Fdate desc) rowNum from ALL_QH a join LGLK_QXDTB q on a.qh= Fwqbh JOIN LGLK_RECORDS ON q.Fsjbm=LGLK_RECORDS.Fsjbm
where 1=1 and LGLK_RECORDS.Fmjsj not like '%关%'
and q.Fcrfs!='在位' and a.zt='离位' ) t where rowNum=1
------------------
partition by 后面就是根据什么分组,order by后面是根据什么来排序