• 博客园logo
  • 会员
  • 周边
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
菲儿——看时间流逝,风不止
博客园    首页    新随笔    联系   管理    订阅  订阅

查询某时间段的统计数据

 begin
DECLARE @CreateTime datetime,@EndTime datetime
SET @CreateTime=  Convert(varchar(10),getdate()-7,120)
SET @EndTime=Convert(varchar(10),getdate(),120)


 select b.[date],COUNT(a.UserID_int) as 人数 
from  ( select convert(varchar(10),dateadd(day,number,@CreateTime),120)  as [date] 
from master..spt_values  
where datediff(day,dateadd(day,number,@CreateTime), @EndTime)>=0 
and number>=0      
and type='p') as b left join OED_User as a on convert(varchar(10),a.CreateTime_datetime,120)=b.[date]  and ISNULL(a.IsEnable_bit,0)=1
group by b.[date]
order by b.[date]
end 
posted @ 2016-07-26 16:01  时间都疯了,你知道吗?  阅读(1255)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3