Skip to main content

Other Things

Menu

Skip to content
  • Home
  • About
  • Projects

Getting Min Max ids after splitting SQL table into n equal parts using ntile

June 10, 2020
Adam Zolo
SQL No Comments

This will split your_table into 10 equal parts, and give you the minimum and maximum id for each part:

with cte as
(
select
id,
ntile(10) over(order by a.id) as bucket_id
from your_table as a
group by a.id
)

select bucket_id, min(id), max(id)
from cte
group by bucket_id
order by bucket_id

Post navigation

Categories

  • Agile (1)
  • AI (2)
  • angular (1)
  • C# (7)
  • Data Science (1)
  • Development Setup (2)
  • docker (4)
  • Elixir (8)
  • Elm (5)
  • Entity Framework (1)
  • git (3)
  • Homelab (2)
  • JavaScript (6)
  • Linux (5)
  • Machine Learning (3)
  • Minecraft (1)
  • MVC (3)
  • Performance (2)
  • Phoenix (4)
  • Python (1)
  • Rails (19)
    • Active Storage (1)
  • React (1)
  • Ruby (17)
  • Security (2)
  • SQL (6)
  • Stripe (1)
  • TFS (1)
  • Uncategorized (13)
  • Web (11)
  • Xamarin (2)

Posts by Date

June 2020
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  
« Dec   Aug »

Proudly powered by WordPress