Search code examples
sqloracle-sqldeveloper

Oracle SQL query to get the max logins per hour from am_session table


How to get the max logins per hour from am_session table which has columns : userid, create_time (datatype:timestamp(6)).

Attached the sample data.

Sample data

Thanks in advance


Solution

  • You can do as below -

    select 
    to_char(create_time, 'YYYY-MM-DD') as create_date, 
    extract(hour from create_time) as Hour,
    Count(*)
    from am_session
    group by 
    to_char(create_time, 'YYYY-MM-DD'),
    extract(hour from create_time)
    order by 1, 2 desc;
    

    Note : This will not provide you count for hours where there was no login.