I have a table with columns:
timeInMilliseconds | price
And I want to create OHLC (Open, High, Low, Close) candles from it. That is basically group all the prices from some period of time (let's say every 1 minute) and select the min, max and first and last price of them.
I have created this query so far:
SELECT
MIN(price) as low,
MAX(price) as high,
FLOOR(timeInMilliseconds/(1000*60)) as open_time
FROM ticks
GROUP BY FLOOR(timeInMilliseconds/(1000*60))
And that works, but the problem is the Open (first) and Close (last) price.
Is there someway to get them in the same query (efficiently)?