Skip to content

Instantly share code, notes, and snippets.

@amacal
Created November 25, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacal/9a659cb3d0c5b7c8a801152c631ca5a7 to your computer and use it in GitHub Desktop.
Save amacal/9a659cb3d0c5b7c8a801152c631ca5a7 to your computer and use it in GitHub Desktop.
with source as
(
select * from ecds_db.playground.time11M
),
timeline as
(
select id, start_at as happened_at, 1 as balance
from source
union all
select id, end_at as happened_at, -1 as balance
from source
),
concurrency as
(
select id, happened_at, balance, sum(balance) over (partition by 1 order by happened_at, id, balance desc rows between unbounded preceding and current row) as count
from timeline
)
select max(count)
from concurrency
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment