按季度或周或旬汇总的问题

zxtyhy 2007-05-26 05:44:33
在oracle中如何实现以上的问题?

例如有表:

ADate AValue
2006-12-5 8
2007-1-1 10
2007-3-8 110
2007-5-10 18
.....

如何得到:
2006四季度 8
2007一季度 120
2007二季度 18
....
...全文
239 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
icefirelxb 2007-05-29
  • 打赏
  • 举报
回复
SELECT to_char(ADate,'yyyy')||'年'||to_char(ADate,'q')||'季度' as 季度,sum(AValue) as total from tablename
group by to_char(ADate,'yyyy')||'年'||to_char(ADate,'q')||'季度'

SELECT to_char(ADate,'yyyy')||'年'||to_char(ADate,'iw')||'周' as 周,sum(AValue) as total from tablename
group by to_char(ADate,'yyyy')||'年'||to_char(ADate,'iw')||'周'

SELECT to_char(ADate,'yyyy')||'年'||to_char(ADate,'mm')||'月'
|| case when to_char(ADate,'dd')<=10 then '上旬' when to_char(ADate,'dd')>20 then '下旬' else '中旬' end
as 旬,sum(AValue) as total from tablename
group by to_char(ADate,'yyyy')||'年'||to_char(ADate,'mm')||'月'
|| case when to_char(ADate,'dd')<=10 then '上旬' when to_char(ADate,'dd')>20 then '下旬' else '中旬' end
zhy19806 2007-05-29
  • 打赏
  • 举报
回复
select to_char(t.adate, 'yyyy')||'年'||to_char(sysdate, 'Q')||'季度',sum(t.avalue) from t
group by to_char(t.adate,'Q')
bjt_ 2007-05-26
  • 打赏
  • 举报
回复
select trunc(t.adate,'Q'),sum(t.avalue) from t
group by trunc(t.adate,'Q')

17,090

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧