sql 语句求助
表中有个日期字段(包括时间),想要统计每个日期之前所有的用户数(包括当天)
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