展开全部
mysql环境4102下:
set @1653rank:=0;
set @CI:=null;
select Id,SN,CreateDate,DayUse from
(
select Id,SN,CreateDate,dayUse,rank from(select Id,SN,CreateDate,dayUse,@rank:=if(@CI=CreateDate,@rank+1,1) as rank,@CI:=CreateDate from table_a
order by SN,CreateDate,dayUse desc) as t1
) a
where rank=1;
原答案:专
sql server环境属下:
select ID,SN,CreateDate,dayUse from
(
select ID,SN,CreateDate,dayUse,
row_number() over(partition by SN,CreateDate order by dayUse desc) as RowNum
from table1
) a
where RowNum=1