Solved

Increment Sequence Number through SQL

Posted on 2011-02-15
2
915 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 500 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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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.

749 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