如何根据日期排序取最大或最小日期所对应的行记录的方法分享


摘要:
下文讲述使用SQL脚本,按照日期排序获取最大或最小日期所对应的行数据的方法,如下所示:
实验环境:sql server 2008、MySQL


  ---最大纪录行
  select keyId,info,writeDate from [maomao365.com] A  
      where writeDate=(select max(writeDate) from [maomao365.com] B
       where A.[info]=B.[info]
      )

  ---最小纪录行
     select keyId,info,writeDate from [maomao365.com] A  
      where writeDate=(select min(writeDate) from [maomao365.com] B
       where A.[info]=B.[info]
      )