ORACLE里面按旬统计怎么GROUP BY?

sxlcj 2003-09-29 02:11:56
select to_char(datefield,'yyyy-mm-dd'),count(*) from mytable group by
to_char(datefield,'yyyy-mm-dd'),是按天统计,按旬怎么写?
...全文
291 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ahalf 2003-10-02
  • 打赏
  • 举报
回复
使用维试试
zzxxdd 2003-10-02
  • 打赏
  • 举报
回复
up
tsj68 2003-09-30
  • 打赏
  • 举报
回复
呵呵,bobfang的语句挺不错的.
我的语句是有问题,把1-9日算到第0旬,10-19算到第1旬,20-29算到第2旬,30-31日算到第3旬了.
可以这样改一下:

select decode(to_char(datefield-1,'yyyy-mm-d'),0,'上旬',1,'中旬','下旬'),count(*) from mytable group by decode(to_char(datefield-1,'yyyy-mm-d'),0,'上旬',1,'中旬','下旬')

sxlcj 2003-09-29
  • 打赏
  • 举报
回复
多谢bobfang
bobfang 2003-09-29
  • 打赏
  • 举报
回复
select to_char(datefield,'yyyy'),
to_char(datefield,'mm'),
decode(trunc((to_char(datefield,'dd')-1)/10),0,'上旬',1,'中旬','下旬'),
count(*)
from mytable
group by to_char(datefield,'yyyy'),
to_char(datefield,'mm'),
decode(trunc((to_char(datefield,'dd')-1)/10),0,'上旬',1,'中旬','下旬');
bzszp 2003-09-29
  • 打赏
  • 举报
回复
select to_char(datefield,'yyyy-mm-dd'),count(*) from mytable group by
to_char(datefield,'yyyy'), to_char(datefield,'mm'), decode(trunc(to_char(datefield,'dd')-1/10),0,'上旬',1,'中旬','下旬');
sxlcj 2003-09-29
  • 打赏
  • 举报
回复
select to_char(datefield,'yyyy-mm-d'),count(*) from mytable group by to_char(datefield,'yyyy-mm-d')统计出来的结果是按星期分组,不是按旬
sxlcj 2003-09-29
  • 打赏
  • 举报
回复
我测试一下tsj68说的.
tsj68 2003-09-29
  • 打赏
  • 举报
回复
select to_char(datefield,'yyyy-mm-d'),count(*) from mytable group by to_char(datefield,'yyyy-mm-d')
jiezhi 2003-09-29
  • 打赏
  • 举报
回复
按旬?
不如再添加一個字段,標識該日期是當月的上旬、中旬還是下旬。
然后以該字段進行分組。

17,081

社区成员

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

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