日期:2014-05-17 浏览次数:20508 次
--方法一
;with Tmp as (
select Date,max(ID) as MaxID from [Table] group by Date
)
update [Table] set Mark = 1
from [Table] A inner join Tmp B ON A.Date = B.Date AND A.id = B.MaxID
--方法二
;with Tmp as (
select row_number() over (partition by Date order by XXX desc ) as Row Date,ID from [Table]
)
update [Table] set Mark = 1
from [Table] A inner join Tmp B ON A.Date = B.Date AND A.id = B.MaxID and b.Row = 1
--最简单的
select right(convert(varchar(16),max(ID)),len(convert(varchar(16),max(ID))) -8) as MaxID
from [Table] group by Date
update t1 set t1.Mark=1
from tbl t1
where exists (select 1 from (
select max(xxx)xxx,convert(varchar(10),datetime,120) datetime
from tbl
group by convert(varchar(10),datetime,120)) t2 where t1.xxx=t2.xxx and convert(varchar(10),t1.datetime,120)=convert(varchar(10),t2.datetime,120))