Skip to content

Instantly share code, notes, and snippets.

@xescuder
Created January 21, 2024 13:13
Show Gist options
  • Save xescuder/b750af70a448a793024ca17fff07b982 to your computer and use it in GitHub Desktop.
Save xescuder/b750af70a448a793024ca17fff07b982 to your computer and use it in GitHub Desktop.
Return changes between today and 1 year ago
SELECT s.symbol, s.sector, first(close, date) AS first_close, last(close, date) AS last_close,
MIN(date) AS first_date,
MAX(date) AS last_date,
100 * (last(close, date) - first(close, date)) / first(close, date) AS return_change
FROM
daily_bars db, stocks s
WHERE
db.date >= now() - interval '1 year' AND db.symbol = s.symbol
GROUP BY
s.symbol
ORDER BY
return_change DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment