Search code examples
sqloracle-databasetimeservicetimestamp

SQL for oracle query get time most service bookings are booked


im try to write a query for when the most popular booking_time of a service is. or when are more services required? The booking time is in a time stamp data type like this: '09-JAN-20 09.00.00.000000 AM' and I know that most bookings are at 0900 but how do I draw that element out, without changing the table. The table is 'Orders' and the column is 'Booking_time'

Thank you


Solution

  • If you want to break down the bookings by hour, you can use to_char() or extract() and then aggregate:

    select to_char(booking_time, 'HH24:00') as hh, count(*)
    from t
    group by to_char(booking_time, 'HH24:00')
    order by hh desc;