3

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
Cœur
  • 34,719
  • 24
  • 185
  • 251
saran
  • 45
  • 5
  • 1
    There is still problem.you have not mention in which scenario you want such sequence. What is the actual query like ?Knowing that can make query easier . – KumarHarsh Jan 02 '15 at 06:29

1 Answers1

17

Use this Analytic function

SELECT ( ( Row_number()OVER(ORDER BY order_by_column ) - 1 ) / 3 ) + 1 seq_no,
              *
       FROM   tablename
Pரதீப்
  • 88,697
  • 17
  • 124
  • 160