John M.
03/08/2023, 8:13 PMSELECT
time,
sym,
first(price) as price
FROM trade
WHERE
time BETWEEN '2023-03-08 12:00:00' AND '2023-03-08 12:02:00' AND
sym='BTC.USD'
SAMPLE BY 1T
ORDER BY time ASC, sym ASC
and I'd love to have an additional column something along the lines of "price-first(price) as delta" but nothing I've tried works. if I use a sub-query WITH beforehand and try to query that, doesnt seem to workWITH fp AS (select price from trade where time>'2023-03-08 12:00:00' and sym='BTC.USD' LIMIT -1)
SELECT
time,
sym,
first(price) AS price,
first(price) - fp.price AS delta
FROM trade
WHERE
time BETWEEN '2023-03-08 12:00:00' AND '2023-03-08 12:02:00' AND
sym='BTC.USD'
SAMPLE BY 1T
ORDER BY time ASC, sym ASC
even though this does work:
WITH fp AS (select price from trade where time>'2023-03-08 12:00:00' and sym='BTC.USD' LIMIT -1)
SELECT price FROM fp
Nicolas Hourcard
03/08/2023, 8:49 PMBolek Ziobrowski
03/08/2023, 10:41 PMWITH fp AS (select price from trade where time>'2023-03-08 12:00:00' and sym='BTC.USD' LIMIT -1)
SELECT
time,
sym,
first(price) AS price,
first(price) - fp.price AS delta
FROM fp
CROSS JOIN trade
WHERE
time BETWEEN '2023-03-08 12:00:00' AND '2023-03-08 12:02:00' AND
sym='BTC.USD'
SAMPLE BY 1T
ORDER BY time ASC, sym ASC
John M.
03/08/2023, 10:59 PMBolek Ziobrowski
03/09/2023, 11:26 AMWITH fp AS (select price as first_price from trades where timestamp>'2023-03-08 12:00:00' and symbol='BTC-USD' LIMIT 1)
select timestamp, symbol, price, price - fp.first_price AS delta
from (
SELECT
timestamp,
symbol,
first(price) AS price
FROM trades
WHERE
timestamp BETWEEN '2023-03-08 12:00:00' AND '2023-03-08 12:02:00' AND
symbol='BTC-USD'
SAMPLE BY 1T
) CROSS JOIN fp
ORDER BY timestamp ASC, symbol ASC
Alex Pelagenko
03/09/2023, 11:28 AMJohn M.
03/09/2023, 9:12 PMAlex Pelagenko
03/09/2023, 9:40 PM