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
Post a Comment