Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"I imagine there's a more elegant way to do this using a window function" #40

Open
curiousleo opened this issue Sep 22, 2021 · 0 comments

Comments

@curiousleo
Copy link

https://til.simonwillison.net/sql/cumulative-total-over-time says:

I imagine there's a more elegant way to do this using a window function but this works fine.

I was looking at queries of this sort recently. Here would be my suggestion:

select
  created_at,
  count(*) over (
    order by
      created_at
  ) as cumulative
from
  repos
where
  "owner" = :owner
order by
  created_at desc

It seems to run a little faster than the original query too.

Example query

I'd have written you an e-mail but couldn't find one on your website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant