试试
select imonth,cinvcode from UFDATA_202_2017.dbo.ia_summary where (imonth+cinvcode) in (select cinvcode+max(imonth) from UFDATA_202_2017.dbo.ia_summary group by cinvcode)