访问记录表 visit_t 字段:id,item_id(访问的节目),vs_date(访问日期时间)
假如有如下数据:
id item_id vs_date
1 100 2006-1-1 00:01:00
2 101 2006-1-1 00:03:00
3 100 2006-1-2 12:00:00
4 102 2006-2-1 12:00:00做如下统计
1.按日分24时段统计
2.按月分天统计
3.按年分月统计预期结果如下:
1.对2006-1-1统计
时段 访问量
00:00:00--01:00:00 2
01:00:00--02:00:00 0
...
2.对2006年1月份统计
日期 访问量
2006-1-1 2
2006-1-2 1
2006-1-3 0
...
3.对2006年统计
月份 访问量
1 3
2 1
3 0
...跪求!
假如有如下数据:
id item_id vs_date
1 100 2006-1-1 00:01:00
2 101 2006-1-1 00:03:00
3 100 2006-1-2 12:00:00
4 102 2006-2-1 12:00:00做如下统计
1.按日分24时段统计
2.按月分天统计
3.按年分月统计预期结果如下:
1.对2006-1-1统计
时段 访问量
00:00:00--01:00:00 2
01:00:00--02:00:00 0
...
2.对2006年1月份统计
日期 访问量
2006-1-1 2
2006-1-2 1
2006-1-3 0
...
3.对2006年统计
月份 访问量
1 3
2 1
3 0
...跪求!
WHERE trunc(vs_date) = DATE '2006-1-1'
group by trunc(vs_date,'hh24')2、select trunc(vs_date),COUNT(*) FROM visit_t
WHERE to_char(vs_date,'yyyy-mm') = '2006-01'
group by trunc(vs_date)3、select trunc(vs_date,'month'),COUNT(*) FROM visit_t
WHERE to_char(vs_date,'yyyy') = '2006'
group by trunc(vs_date,'month')
insert into tttt values(1,'100',to_date('2006-1-1 00:01:00','yyyy-mm-dd hh24:mi:ss'));
insert into tttt values(2,'101',to_date('2006-1-1 00:03:00','yyyy-mm-dd hh24:mi:ss'));
insert into tttt values(3,'100',to_date('2006-1-2 12:00:00','yyyy-mm-dd hh24:mi:ss'));
insert into tttt values(4,'102',to_date('2006-2-1 12:00:00','yyyy-mm-dd hh24:mi:ss'));
commit ;
3:
select to_char(vs_date,'yyyy')as 年份,to_char(vs_date,'mm')as 月份,count(1)as 访问量 from tttt
group by to_char(vs_date,'yyyy'),to_char(vs_date,'mm');
2:
select to_char(vs_date,'yyyy-mm-dd')as 日,count(1)as 访问量 from tttt
group by to_char(vs_date,'yyyymm'),to_char(vs_date,'yyyy-mm-dd');
1:
select to_char(to_date(a.datetime,'yyyy-mm-dd hh24'),'yyyy-mm-dd hh24:mi:ss'), a.fcount ,to_char((to_date(a.datetime,'yyyy-mm-dd hh24')+1/24),'yyyy-mm-dd hh24:mi:ss')
from (select to_char(vs_date,'yyyy-mm-dd hh24')as datetime,count(1)as fcount from tttt
group by to_char(vs_date,'yyyy-mm-dd hh24'))a;