Solved

Increment Sequence Number through SQL

Posted on 2011-02-15
2
909 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
2 Comments
 
LVL 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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…
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 how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now