Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Break Numbers List Into Min and Max Ranges

Brain is not working today and my google skills are failing me.

I have a column of numbers ranging from 1 - 1000. I want to dump the min and max values for 100 (or whatever I chose) record ranges into a temp table. The plan is to use this temp table to process ranges of records (in this example 100 at a time) in a larger table.

Swear I have done this before with a CTE but then I had something to group on. Here I just want to break up a single list of numbers into ranges of X.

The output from the temp table should look like:

Min Max 0 99 100 199 200 299 300 399

etc.

Thanks!

like image 308
mnDBA Avatar asked Nov 23 '25 14:11

mnDBA


1 Answers

You can use this trick from Stuart Ainsworth:

http://codegumbo.com/index.php/2009/01/25/building-ranges-using-a-dynamically-generated-numbers-table/

Numbers tables are awesome, but he uses a dynamically generated numbers table, which is even awesome...r.

like image 99
Brent Ozar Avatar answered Nov 27 '25 15:11

Brent Ozar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!