Skip to content

Instantly share code, notes, and snippets.

@zseta
Created December 27, 2021 13:37
Show Gist options
  • Save zseta/f14946f95262f2494942f68a5deca222 to your computer and use it in GitHub Desktop.
Save zseta/f14946f95262f2494942f68a5deca222 to your computer and use it in GitHub Desktop.
/*
If last close exists: open = last_close, else open = first(price)
*/
SELECT
time_bucket('1 day', time) AS bucket,
symbol,
CASE
WHEN LAST(price_close, time) IS NOT NULL THEN LAST(price_close, time)
ELSE FIRST(price_open, time)
END AS price_open
FROM stocks_intraday
GROUP BY bucket, symbol
LIMIT 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment