1. <small id='8ufck'></small><noframes id='8ufck'>

        <bdo id='8ufck'></bdo><ul id='8ufck'></ul>
    2. <legend id='8ufck'><style id='8ufck'><dir id='8ufck'><q id='8ufck'></q></dir></style></legend>
    3. <tfoot id='8ufck'></tfoot>

        <i id='8ufck'><tr id='8ufck'><dt id='8ufck'><q id='8ufck'><span id='8ufck'><b id='8ufck'><form id='8ufck'><ins id='8ufck'></ins><ul id='8ufck'></ul><sub id='8ufck'></sub></form><legend id='8ufck'></legend><bdo id='8ufck'><pre id='8ufck'><center id='8ufck'></center></pre></bdo></b><th id='8ufck'></th></span></q></dt></tr></i><div id='8ufck'><tfoot id='8ufck'></tfoot><dl id='8ufck'><fieldset id='8ufck'></fieldset></dl></div>

        计算oracle中两个日期之间每小时的记录数

        时间:2024-04-16

          • <bdo id='CFPsF'></bdo><ul id='CFPsF'></ul>
          • <tfoot id='CFPsF'></tfoot>

              <small id='CFPsF'></small><noframes id='CFPsF'>

                  <i id='CFPsF'><tr id='CFPsF'><dt id='CFPsF'><q id='CFPsF'><span id='CFPsF'><b id='CFPsF'><form id='CFPsF'><ins id='CFPsF'></ins><ul id='CFPsF'></ul><sub id='CFPsF'></sub></form><legend id='CFPsF'></legend><bdo id='CFPsF'><pre id='CFPsF'><center id='CFPsF'></center></pre></bdo></b><th id='CFPsF'></th></span></q></dt></tr></i><div id='CFPsF'><tfoot id='CFPsF'></tfoot><dl id='CFPsF'><fieldset id='CFPsF'></fieldset></dl></div>

                  <legend id='CFPsF'><style id='CFPsF'><dir id='CFPsF'><q id='CFPsF'></q></dir></style></legend>
                    <tbody id='CFPsF'></tbody>
                  本文介绍了计算oracle中两个日期之间每小时的记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要一个在 oracle 中执行此序列的 SINGLE 查询.

                  I need a SINGLE query that does this sequence in oracle.

                  select count(*) from table1
                  where request_time < timestamp'2012-05-19 12:00:00' and (end_time > timestamp'2012-05-19 12:00:00' or end_time=null);
                  
                  select count(*) from table1
                  where request_time < timestamp'2012-05-19 13:00:00' and (end_time > timestamp'2012-05-19 13:00:00' or end_time=null);
                  
                  select count(*) from table1
                  where request_time < timestamp'2012-05-19 14:00:00' and (end_time > timestamp'2012-05-19 14:00:00' or end_time=null);
                  
                  select count(*) table1
                  where request_time < timestamp'2012-05-19 15:00:00' and (end_time > timestamp'2012-05-19 15:00:00' or end_time=null);
                  
                  select count(*) from table1
                  where request_time < timestamp'2012-05-19 16:00:00' and (end_time > timestamp'2012-05-19 16:00:00' or end_time=null);
                  

                  如您所见,小时正在一点一点增加.这是输出

                  As you see the hour is increasing one by one. here is the output

                  COUNT(*)               
                  1085                   
                  

                  <小时>

                  COUNT(*)               
                  1233                   
                  

                  <小时>

                  COUNT(*)               
                  1407                   
                  

                  <小时>

                  COUNT(*)               
                  1322                   
                  

                  <小时>

                  COUNT(*)               
                  1237
                  

                  <小时>

                  我写了一个查询,但它没有给我正确的答案!


                  I have written a query but it does not give me the right answer!

                  select col1, count(*) from
                  (select TO_CHAR(request_time, 'YYYY-MM-DD HH24') as col1 from table1
                   where request_time <= timestamp'2012-05-19 12:00:00' and (end_time >= timestamp'2012-05-19 12:00:00' or end_time=null))
                  group by col1 order by col1;
                  

                  这个查询给了我一个结果集,它的 count(*) 的总和等于上面写的第一个查询!结果如下:

                  this query gives me a result set that sum of it's count(*) is equal to the first query written above! here is the result:

                  COL1          COUNT(*)               
                  ------------- ---------------------- 
                  2012-05-19 07      22                     
                  2012-05-19 08      141                    
                  2012-05-19 09      322                    
                  2012-05-19 10      318                    
                  2012-05-19 11      282  
                  

                  推荐答案

                  注意 trunc 表达式与日期值的用法.如果不在 sql*plus 中运行查询,则可以省略 alter session.

                  Note the usage of trunc expression with date values. You can omit the alter session if you are not running the query in sql*plus.

                  SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
                  
                  Session altered.
                  
                  SQL> SELECT 
                         trunc(created,'HH'), 
                         count(*) 
                       FROM 
                         test_table 
                       WHERE 
                         created > trunc(SYSDATE -2) 
                       group by trunc(created,'HH');
                  
                  
                  TRUNC(CREATED,'HH')   COUNT(*)
                  ------------------- ----------
                  2012-05-21 09:00:00        748
                  2012-05-21 16:00:00         24
                  2012-05-21 17:00:00         12
                  2012-05-21 22:00:00        737
                  2012-05-21 23:00:00        182
                  2012-05-22 20:00:00         16
                  2012-05-22 21:00:00        293
                  2012-05-22 22:00:00        610
                  
                  8 ROWS selected.
                  

                  这篇关于计算oracle中两个日期之间每小时的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 SQLite 中按月分组 下一篇:MySQL 删除与分组依据

                  相关文章

                  <i id='jQSDM'><tr id='jQSDM'><dt id='jQSDM'><q id='jQSDM'><span id='jQSDM'><b id='jQSDM'><form id='jQSDM'><ins id='jQSDM'></ins><ul id='jQSDM'></ul><sub id='jQSDM'></sub></form><legend id='jQSDM'></legend><bdo id='jQSDM'><pre id='jQSDM'><center id='jQSDM'></center></pre></bdo></b><th id='jQSDM'></th></span></q></dt></tr></i><div id='jQSDM'><tfoot id='jQSDM'></tfoot><dl id='jQSDM'><fieldset id='jQSDM'></fieldset></dl></div>

                    <bdo id='jQSDM'></bdo><ul id='jQSDM'></ul>
                    1. <legend id='jQSDM'><style id='jQSDM'><dir id='jQSDM'><q id='jQSDM'></q></dir></style></legend><tfoot id='jQSDM'></tfoot>

                      <small id='jQSDM'></small><noframes id='jQSDM'>