sql server - SQl Query to break results into specifically sized groups -


i need write query identify 5 groups of different size. know can use ntile break set equal size groups need this

total records 1,000,000  group 1 100,000 rows group 2 200,000 rows group 3 300,000 rows group 4 400,000 rows 

thanks

well, use row_number() , logic on top of that:

select (case when seqnum <= 100000 'group1'              when seqnum <= 100000 + 200000 'group2'              when seqnum <= 100000 + 200000 + 300000 'group3'              when seqnum <= 100000 + 200000  + 300000 + 400000 'group4'          end) groupname,        t.* (select t.*,              row_number() on (order <your criteria>) seqnum       t      ) t 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -