select *,dateadd(month,12,LJ_DATE)
from tb as t
where not exists(select * from tb where CPCODE=t.CPCODE and LJ_DATE>t.LJ_DATE)

解决方案 »

  1.   

    select cpcode,sy_Ym,LJ_DATE=min(LJ_Date),LJ_DATE+12个月的日期=dateadd(mm,12,min(LJ_Date)) from tab group by ode,sy_Ym
      

  2.   

    select cpcode, sb_ym, lj_date = min(lj_date), dateadd(month,12,min(lj_date))
    from tb
    group by cpcode, sb_ym
      

  3.   


    select *,dateadd(month,12,LJ_DATE)
    from tb as t
    where not exists(select * from tb where CPCODE=t.CPCODE and LJ_DATE<t.LJ_DATE)
      

  4.   

    select 
        t.*,dateadd(mm,12,t.LJ_DATE)
    from
        tabname t
    where
        not exists(select 1 from tabname where CPCODE=t.CPCODE and SB_YM=t.SB_YM and LJ_DATE<t.LJ_DATE)