帮帮我看看能不能改写这条sql.
帮帮我看看能不能改写这条sql.
谢谢.
有一个这样的表 t
id timed clicksum
1 2006-6-29 9:00:00.123 10
2 2006-6-29 10:01:00.123 20 (当天最高.max)
3 2006-6-29 11:00:00.21 15
....
....
....
28 2006-7-1 01:00:00.21 20
要求是这样的.我要对这个表构造成这样的数据分析:
datetime clicksum(当天点击数最高) 0点点击量... 10点点击量 23点点击量
2006-6-29 20 20
.
.
2006-7-1 .....
我是这样写的
select distinct trunc(timeo), (select max(clicksum) 当天最高点击数 from test.t t
where timeo between to_date('2006-6-26','yyyy-mm-dd')
and to_date('2006-6-27','yyyy-mm-dd') ),
(select clicksum from test.t where timeo
between to_date('2006-6-26 10:00:00','yyyy-mm-dd hh24:mi:ss')
and to_date('2006-6-26 10:59:59','yyyy-mm-dd hh24:mi:ss')) "10点点击",
(select clicksum from test.t where timeo
between to_date('2006-6-26 11:00:00','yyyy-mm-dd hh24:mi:ss')
and to_date('2006-6-26 11:59:59','yyyy-mm-dd hh24:mi:ss')) "11点点击"
from test.t
where timeo
between to_date('2006-6-26','yyyy-mm-dd')
and to_date('2006-6-27','yyyy-mm-dd')
/*上面的是26号统计*/
/*27号我用union all并起来,*/
union all
/*27号sql*/
有什么办法优化这条sql?谢谢.
问题点数:50、回复次数:4Top
1 楼qqkkqqkkqqkk123(dsafds)回复于 2006-07-02 19:07:12 得分 0
有没有什么函数 能做到啊?Top
2 楼fjmingyang(努力升级)回复于 2006-07-02 19:09:41 得分 0
为什么不用group byTop
3 楼qqkkqqkkqqkk123(dsafds)回复于 2006-07-02 19:38:35 得分 0
用group by 能行,不过只能统计当天的数据...第二天的,都只是26号的Top
4 楼yqwd911(windy)回复于 2006-07-03 09:12:22 得分 0
应该用
case when ... then ...
when ... then ...
else ... end
的语句Top




