当前位置: 代码迷 >> Java Web开发 >> 求SQL实现 按日期/时间 显示不同时刻,登陆某网站的人数,该怎么处理
  详细解决方案

求SQL实现 按日期/时间 显示不同时刻,登陆某网站的人数,该怎么处理

热度:742   发布时间:2016-04-17 13:06:35.0
求SQL实现 按日期/时间 显示不同时刻,登陆某网站的人数
日期                                                         时间
                            0-1点       1-2点       2-3点     3-4点         4-5点.....             23-24点
2007-08-27             20             24           28           13               8                                 33  
2007-08-28             12             54           45           14               8                                 43    
2007-08-29             32             23           28           23               32                               34  
2007-08-30             12             34           43           14               42                               23
2007-08-31             22             23           28           13               8                                 33  
...                

按日期/时间   显示不同时刻,登陆某网站的人数
表中有   记录着     登陆人的   id       和   登陆时间

------解决方案--------------------
select count(id) from table group by 时间(取小时)
------解决方案--------------------
select t1.id,t2.num1,t3.num2,t4.num3 from tablename t1
left join (select id,count(id) as num1 from tableNmae where substring(date,12,2) > =0 and substring(date,12,2) <1) t2 on t1.id=t2.id
left join (select id,count(id) as num2 from tableNmae where substring(date,12,2) > =1 and substring(date,12,2) <2 ) t3 on t1.id=t3.id

left join (select id,count(id) as num3 from tableNmae where substring(date,12,2)> =2 and substring(date,12,2) <3 ) t4 on t1.id=t4.id

group by substring(date,0,10) 试试能不能通过编译,我的没有Sql server


  相关解决方案