sql - Insert values into a new table with "position in group" column? -
i have table:
c1 c2 c3 ---------- 100 200 100 201 100 203 200 405 200 408
...and table created 3 columns.
i need add values above table new table including new column like,
c1 c2 c3 -------------- 100 200 1 100 201 2 100 203 3 200 405 1 200 408 2
...and on. c3
dependent on c1
, when c1
changed, set 1 , continue increment.
the second table created , empty.
need copy values of columns c1
, c2
of old table new table , @ same time, insert new values c3
of second table.
insert my_table2 select c1, c2 ,row_number() on (partition c1 order c1, c2) my_table
Comments
Post a Comment