Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to add a number column

Status
Not open for further replies.

sachin05

Programmer
Jun 18, 2001
3
US
I want to add a column to my select statement that would generate
consecutive numbers:

for example:

Col1 Col2
user1 1
user2 2
user3 3
user4 4

(need to generate col2)

any ideas?
sachin
 
From the snippet of your table definition and records shown this should work but might need some slight modification if they are more involved. I’m assuming User1 to 4 is a unique id.

select a.Col1,
(select count(distinct b.Col1) from Tablename b
where (a.Col1 >= b.Col1)) as Col2
from Tablename a
order by a.Col1

Rick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top