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
  • 37,241
  • 25
  • 195
  • 267
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

18

Use this Analytic function

SELECT ( ( Row_number()OVER(ORDER BY order_by_column ) - 1 ) / 3 ) + 1 seq_no,
              *
       FROM   tablename
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172