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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Row Count

Status
Not open for further replies.

ADB1

Programmer
Aug 24, 2001
235
GB
Is ther a function in Teradata SQL to bring back a column which allocates a consecutive number to rows returned ie. 1,2,3,4,5 and so on.

Thanks,

Adam.
 
Use the CSUM function, for example:

Select Name, CSUM(1,1)
From Table1
Order By 1;

You may need to play with the order by and the second 1 (sort column ) in the CSUM function to get the rows ordered the way you want.

The RANK function also works:

Select Name, RANK(Name)
From Table1
Oder By 1;

The problem with RANK is the ranking column MUST BE unique for the values to be unique, for exampl if two people have the nane Smith, they both get the same RANK.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top