日期:2014-05-17 浏览次数:20411 次
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (FID int,FDate datetime)
insert into [TB]
select 1,'2013-1-1 08:00:00' union all
select 2,'2013-1-1 08:30:00' union all
select 3,'2013-1-1 08:35:00' union all
select 4,'2013-1-2 09:00:00'
select * from [TB]
SELECT *, ROW_NUMBER() over(PARTITION BY convert(VARCHAR(10),fdate,120) ORDER BY fdate) AS Fnum
FROM TB
/*
FID FDate Fnum
1 2013-01-01 08:00:00.000 1