简体   繁体   中英

oracle datetime group by

I want to group data based on date time in oracle eg:-

03-DEC-13 06:12:03:23,
03-DEC-13 06:12:03:25,
04-DEC-13 08:12:03:23,
04-DEC-13 08:12:03:25

expected result :- 03-DEC-13 06:12:03, 04-DEC-13 08:12:03

neglect seconds.

SELECT DISTINCT trunc(some_date, 'MI') FROM some_table;

Question is not completely clear, but I think something like:

select to_char(datefield, 'DD-MMM-YY HH24:MI') , count(*) /* or other grouping */
from   table 
group by to_char(datefield, 'DD-MMM-YY HH24:MI')

If you want to include date/times for which you don't have a value, use something like join with a calendar table or a join with

select  to_date('20000101', 'YYYYMMDD') + level / 24 day_and_hours
from    dual
connect by level <= 100

Check your performance when doing so.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM