日期:2014-05-17  浏览次数:20963 次

写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
nvl(sum(decode(to_char(登陆时间, 'hh24 '),0,1,0)),0),
nvl(sum(decode(to_char(登陆时间, 'hh24 '),0,2,0)),0),
nvl(sum(decode(to_char(登陆时间, 'hh24 '),0,3,0)),0),
...
nvl(sum(decode(to_char(登陆时间, 'hh24 '),0,23,0)),0)
from 表 group by trunc(登陆时间)