sql >> Database teknologi >  >> RDS >> Mysql

Gruppering i interval på 5 minutter inden for et tidsinterval

Dette virker med hvert interval.

PostgreSQL

SELECT
    TIMESTAMP WITH TIME ZONE 'epoch' +
    INTERVAL '1 second' * round(extract('epoch' from timestamp) / 300) * 300 as timestamp,
    name,
    count(b.name)
FROM time a, id 
WHERE …
GROUP BY 
round(extract('epoch' from timestamp) / 300), name


MySQL

SELECT
    timestamp,  -- not sure about that
    name,
    count(b.name)
FROM time a, id 
WHERE …
GROUP BY 
UNIX_TIMESTAMP(timestamp) DIV 300, name


  1. Sådan installeres Azure Data Studio på en Mac

  2. Oracle dato til streng konvertering

  3. Oracle GROUP_CONCAT() ækvivalent

  4. Gendan en SQL Server-database (T-SQL)