1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] SQL VERTICA group by intervals

Discussão em 'Outras Linguagens' iniciado por Stack, Novembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    How to group records by interval 4 hours?

    For example, I have rows that contain data about events durations.

    event_id start_date end_date
    1 2024-08-16 14:30:00 2024-08-16 16:00:00
    1 2024-08-16 16:00:00 2024-08-16 17:30:00
    1 2024-08-16 17:30:00 2024-08-16 19:00:00
    1 2024-08-16 19:00:00 2024-08-16 20:30:00
    1 2024-08-16 20:30:00 2024-08-16 22:00:00
    1 2024-08-16 22:00:00 2024-08-16 23:30:00

    I want to group them but max duration of 1 row should be 4 hours.

    Result:

    event_id start_date end_date
    1 2024-08-16 14:30:00 2024-08-16 17:30:00
    1 2024-08-16 17:30:00 2024-08-16 20:30:00
    1 2024-08-16 20:30:00 2024-08-16 23:30:00

    I tried to use something like this to display an increased duration but no idea how to use it for grouping

    select sum(end_date - start_date) over (partition by event_id order by start_date)

    Continue reading...

Compartilhe esta Página