R
R
Roman Rakzin2017-10-29 22:40:45
PostgreSQL
Roman Rakzin, 2017-10-29 22:40:45

How to group a table by minute (hourly)?

There is a table with fields: market, time, trading volume.
How to group hourly each market displaying trades for a given hour?
I.e

Рынок1 в 12:00  1000
    Рынок1 в 12:20  1100
    Рынок1 в 12:50  1400
    Рынок1 в 13:10  1450
    Рынок2 в 12:00  300

In response I want to get

Рынок1  12:00  1400
    Рынок1  13:00  1450
    Рынок2  12:00  300

Or in another way - a state for 12 hours for 13 hours ...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
nozzy, 2017-10-29
@nozzy

SELECT
рынок,
SUM(объём_торгов),
TIMESTAMPADD(HOUR,TIMESTAMPDIFF(HOUR,CURDATE(),время),
    CURDATE()) AS round_date,
FROM your_table
GROUP BY рынок, round_date

A
Alexander Pryadko, 2017-10-29
@alexander_v_pryadko

select hour and group by this column

0
0xD34F, 2017-10-29
@0xD34F

SELECT рынок, date_trunc('hour', время), объём_торгов
FROM таблица
WHERE (время, рынок) IN (
  SELECT max(время) AS время, рынок
  FROM таблица
  GROUP BY date_trunc('hour', время), рынок
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question