Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Increment Sequence Number through SQL

Posted on 2011-02-15
2
Medium Priority
?
926 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
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 shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

636 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