oracle如何写这样一条sql语句

oFengKun 2013-09-22 05:39:27
oracle如何查询一条按照周来过滤的结果集:例如查询2013年8月第2周的所有数据,
table表中有一个字段insert_time存放的是插入时间,请问sql如何写? 另外hql如何写?
...全文
268 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yunbird 2013-09-29
  • 打赏
  • 举报
回复
select *
  from table t
 where to_char(t.insert_time, 'mm') = 8
   and to_char(t.insert_time, 'w') = 2;
lqscoke 2013-09-28
  • 打赏
  • 举报
回复
看1楼的,还想回复下,看到3楼后,就没话说了。大神们都解答了!
  • 打赏
  • 举报
回复
月份和周数 都可以已参数的方式传进来进行查询

with t1 as
(
     select date'2013-08-02' c1 from dual union all
     select date'2013-08-05' c1 from dual union all
     select date'2013-08-08' c1 from dual union all
     select date'2013-08-11' c1 from dual union all
     select date'2013-08-22' c1 from dual union all
     select date'2013-08-26' c1 from dual 
)

select *
from t1
where to_char(c1,'w')=2
      and c1 >= to_date('2013-08','yyyy-mm') 
      and c1 < add_months(to_date('2013-08','yyyy-mm'),1)

       c1
-----------------------
1	2013/8/8
2	2013/8/11

  • 打赏
  • 举报
回复
引用 1 楼 lyliu602 的回复:
[quote=引用 楼主 oFengKun 的回复:] oracle如何查询一条按照周来过滤的结果集:例如查询2013年8月第2周的所有数据, table表中有一个字段insert_time存放的是插入时间,请问sql如何写? 另外hql如何写?
这种是很简单的了 1、把你传入的参数,应该是一个日期吧,根据这个日期获得它一周的数据,比如说可今天是9.22,你就获取9.22-9.28的日期 2、然后将第一步获取的日期范围传入到你的查询条件中,select * from table where insert_time between 9.22 and 9.28 像这样不就可了吗?[/quote] oracle中有个函数to_char(字段,'w')
liu112736 2013-09-23
  • 打赏
  • 举报
回复
select * from table where insert_time between to_char(insert_time,'yyyyMMdd')='20130922' and to_char(insert_time,'yyyyMMdd')='20130928'
无敌小二傻 2013-09-22
  • 打赏
  • 举报
回复
引用 楼主 oFengKun 的回复:
oracle如何查询一条按照周来过滤的结果集:例如查询2013年8月第2周的所有数据, table表中有一个字段insert_time存放的是插入时间,请问sql如何写? 另外hql如何写?
这种是很简单的了 1、把你传入的参数,应该是一个日期吧,根据这个日期获得它一周的数据,比如说可今天是9.22,你就获取9.22-9.28的日期 2、然后将第一步获取的日期范围传入到你的查询条件中,select * from table where insert_time between 9.22 and 9.28 像这样不就可了吗?

17,089

社区成员

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

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