How to update column with row_number() in teradata?

Member

by gilbert , in category: MySQL , a month ago

How to update column with row_number() in teradata?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by elise_daugherty , a month ago

@gilbert 

You can update a column with row number in Teradata by using a subquery with the ROW_NUMBER() function. Here is an example query to update a column with row number in Teradata:

1
2
3
4
5
6
7
UPDATE your_table
SET column_name = row_num
FROM (
    SELECT column_name, ROW_NUMBER() OVER (ORDER BY some_column) AS row_num
    FROM your_table
) AS subquery
WHERE your_table.primary_key = subquery.primary_key;


In this query:

  • Replace "your_table" with the name of your table.
  • Replace "column_name" with the name of the column you want to update with row number.
  • Replace "some_column" with the column based on which you want to order the rows.
  • Replace "primary_key" with the primary key of your table.


This query will update the specified column with row numbers based on the specified column order.