SQL Max(date) without group by

前端 未结 1 1969
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-21 00:07

I have the following table...

MemberID  ServDate
001       12-12-2015
001       12-13-2015
001       12-15-2015
002       11-30-2015
002       12-04-2015
         


        
相关标签:
1条回答
  • 2021-01-21 00:43
    SELECT 
      MemberID, ServDate, 
      MAX(ServDate) OVER (PARTITION BY MemberID) AS LastServDate
    FROM Table
    

    Standard SQL, so works in most modern RDBMS (including SQL Server and Oracle).

    EDIT by the way, if you want to learn more: MSDN ref. for OVER

    0 讨论(0)
提交回复
热议问题