?
Solved

Increment Sequence Number through SQL

Posted on 2011-02-15
2
Medium Priority
?
919 Views
Last Modified: 2012-05-11
Hi,

I have a SQL query which will fetch the data in below format. Seq_NUM column is a dynamic column.I have to increment the seq number from one for every new FIELD1 value like below.

Is it possible to do it through SQL?
FIELD1	FIELD2	FIELD3	SEQ_NUM
-----------------------------------------------------------
AAA	name1	phone	1
AAA	name2	phone	2
AAA	name3	phone	3
AAA	name4	phone	4
BBB	name1	phone	1
BBB	name2	phone	2
CCC	name1	phone	1
CCC	name2	phone	2
CCC	name1	phone	3
CCC	name2	phone	4
CCC	name1	phone	5
CCC	name2	phone	6

Open in new window

0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 34895879
this should do:
select FIELD1  , FIELD2  , FIELD3
  ,ROW_NUMBER() OVER (PARTITION BY FIELD1 ORDER BY field2,field3) SEQ_NUM
 from yourtable

Open in new window

0
 

Author Closing Comment

by:Suriyaraj_Sudalaiappan
ID: 34895912
GOOD ONE
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question