sql - Round date to 10 minutes interval -


I have a DATE column that I want to round at the next 10 minute intervals Am a query (see example below).

I managed to do it by deducting the last digit of minutes by reducing it in seconds. Test_data AS (SELECT TO_DATE (SELECT TO_DATE '2010-01-01 10:00:00', 'YYYY-MM-DD HH24: MI: SS') d with double team selected TO_DATE

  From ('2010-01-01 10:05:00', 'YYYY-MM-DD HH 24: MI: SS') d Dual union selection from TO_DATE ('2010-01-01 10:09:59', ' Dual union selective TO_DATE ('2010-01-01 10:10:00', 'YYYY-MM-DD HH24: MI: SS') d from DY-YY-MM-DD HH 24: MI: SS ') d Association selected from TO_DATE ('2099-01-01 10:00:33', 'YYYY-MM-DD HH 24: MI: SS') d) Double-select test-data #end D, TRUN ( D, 'MI') - TO_CHA R (D, 'MI'), 10) / (24 * 60) from Test_data   

And here's the result:

01.01.2010 10 : 00:00 & nbsp; & Nbsp; 01.01.2010 10: 00:00
01.01.2010 10: 05:00 & nbsp; & Nbsp; 01.01.2010 10: 00:00
01.01.2010 10: 09:59 & nbsp; & Nbsp; 01.01.2010 10: 00:00
01.01.2010 10: 10:00 & nbsp; & Nbsp; 01.01.2010 10: 10:00
01.01.20 99 10: 00:33 & nbsp; & Nbsp; 01.01.20 99 10: 00:00

Works as expected, but is there a better way?

Edit :

I was curious about the display, so I did the following tests with 500,000 rows and (in fact) not random dates. I want to add results as comments for the solutions provided.

  Translated time TIMESTAMP: = SYSTIMESTAMP; (IMI) - Choose TODCAR (D, 'MI'), 10) / IOA (as test_data AS (SELECT SYSDATE + ROWNUM / 5000 D to ROWNUM with double connection = 500000) TRUNC (D , 'MI') (24 * 60) from test_data) Loop Nouvelle; End loop; Dbms_output.put_line (SYSTIMESTAMP -T); End;  

This approach received 03.24 s .

 select  trunc (sysdate, 'mi') - numtodsinterval (mod (EXTRACT) ( Dual; minutes (sysdate as timestamp), 10), 'min'); Select trunc (sysdate, 'mi') - mod (excitat (sysdate as timestamp), 10) / or  
  (24 * 60) from dual ;  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -