有一表,其时间类型如 时间 数
2006/01/01 xxx.xx 2006/01/02 xxx.xx 2006/01/03 xxx.xx 2006/01/04 xxx.xx
.... ...
统计结果要如下:
期间 sum数
2006/01/01(星期一)~2006/01/07(星期日) xxx.xx
按自然的星期来统计
2006/01/01 xxx.xx 2006/01/02 xxx.xx 2006/01/03 xxx.xx 2006/01/04 xxx.xx
.... ...
统计结果要如下:
期间 sum数
2006/01/01(星期一)~2006/01/07(星期日) xxx.xx
按自然的星期来统计
解决方案 »
- NB的错误!!!
- 关于Where子句的解析顺序,谢谢大牛指导
- [求助]排除表中的重复数据
- 如何连接远程oracle服务器?
- select count(*) as temp from pre_house where recnum not in (select distinct max(t1.recnum) from pre_house t1 group by t1.righ
- 求救:ORACLE的索引问题
- 为什么中文版oracle,会忽然变成英文版??急!请帮忙!
- ocisessionbegin:error while trying to retrieve text for error ora-24327
- 小问题,大用处!各位来看~
- Oracle 查询今天到前面30天的数据,没有的数据为0
- 关于逻辑运算符的问题????
- 100分收集疑难SQL的经典实现方案!
IW是国际标准的每个新奇第一天.
如果要返还你的要求,只要在再加上trunc(时间,'IW')+6即可.
变为
select to_char(trunc(时间,'IW'),'yyyy/mm/dd')||'(星期一)~'||to_char(trunc(时间,'IW')+6,'yyyy/mm/dd')||'(星期日)',sum(score) from tab group by to_char(trunc(时间,'IW'),'yyyy/mm/dd')||'(星期一)~'||to_char(trunc(时间,'IW')+6,'yyyy/mm/dd')||'(星期日)'
常看sql reference即可解决类似问题.
TRUNC(SYSD
----------
20-11月-06哈哈,学习!
你的方法试过了,好用!学习!按照你的思路,稍微改了点,容易懂一些:
select distinct to_char(trunc(to_date(t.时间), 'IW'), 'yyyy/mm/dd') ||
'(星期一)~' ||
to_char(trunc(to_date(t.时间), 'IW') + 6, 'yyyy/mm/dd') ||
'(星期日)' as dd,
count(*) over(partition by trunc(to_date(t.时间), 'IW')) cnt
from 表 t
order by 1
select distinct to_char(trunc(to_date(t.时间), 'IW'), 'yyyy/mm/dd') ||
'(星期一)~' ||
to_char(trunc(to_date(t.时间), 'IW') + 6, 'yyyy/mm/dd') ||
'(星期日)' as 期间,
sum(t.数) over(partition by trunc(to_date(t.时间), 'IW')) as sum数
from 表 t
order by 1注意:
一定要用‘distinct’。
FROM tab
group by TRUNC(时间 -1,'DAY') +1 ;