科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道按时间段分组查询

按时间段分组查询

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

按时间段分组查询

作者:csdn 来源:csdn 2009年12月22日

关键字: ORACLE 问答

  • 评论
  • 分享微博
  • 分享邮件

按时间段分组查询?

表:ttextinfo
字段:spare6  varchar(50)
      keyno  varchar(50)
      trtime  date
      origin  varchar(1)
要求是这样:查询出从晚上18点到第二天早上8:59:59的数据
SQL codeSQL>select spare6,count(spare6) from ttextinfo where substr(keyno,1,5)='R5101' and to_char(trtime,'yyyymm')='200911'
and to_char(trtime,'hh24miss') btween ('180000'-'235959') and ('000000'-'085959') and origin='1' group by      spare6;

就是不知道那部分时间btween ('180000'-'235959') and ('000000'-'085959')怎么写了,我写出来的记录为空?

 

oracle 日期范围查询问题

select * from aaa where to_char(rq,'yyyymmdd') between '20011101' and '20020301';

直接在rq上加函数,如果应用大(这个表内数据很多时),查询速度会相当慢的,为了提高查询速度,强烈建议这样书写:
select * from aaa where rq between to_date('2001-11-01','yyyy-MM-DD') and to_date('2002-03-01' ,'YYYY-MM-DD');

推荐使用
select * from aaa where rq>;=to_date('2001-11-01','yyyy-MM-DD') and rq <=to_date('2002-03-01' ,'YYYY-MM-DD');

用between的函数可能会慢些

 

select *
  from tpssm01 t
where t.rec_create_time between
      to_char((trunc(sysdate) + 20 / 24), 'yyyymmddhh24miss')--当天的20:00:00
      and
      to_char((((trunc(sysdate + 1) + 9 / 24 - 1 / 86400))),--明天8:59:59
              'yyyymmddhh24miss');

    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章