Reputation: 45
I need to generate a sequence number
for every three rows
with some range. can this be done without iterations.
Example:
sequence
--------
1
1
1
2
2
2
3
3
3
Upvotes: 3
Views: 1014
Reputation: 93734
Use this Analytic function
SELECT ( ( Row_number()OVER(ORDER BY order_by_column ) - 1 ) / 3 ) + 1 seq_no,
*
FROM tablename
Upvotes: 17