sql 语句求助
表中有个日期字段(包括时间),想要统计每个日期之前所有的用户数(包括当天)
2006-11-09 15:31
2006-11-09 16:48
declare @table table
(
uid int,
date datetime
)
insert into @table
select 1,getdate()-1 union all
select 2,getdate()-1 union all
select 3,getdate()-1 union all
select 4,getdate()-2 union all
select 5,getdate()-2 union all
select 6,getdate()-3 union all
select 7,getdate()
select distinct (select count(uid) from @table where date<=a.date) as Totol_U, date from @table a

2006-11-09 17:24
2006-11-09 17:40
2006-11-09 17:41
2006-11-09 17:42
2006-11-09 17:44

2006-11-09 17:45
2006-11-09 17:47
2006-11-09 17:49