日期:2014-05-17  浏览次数:20747 次

向表中插入数据,赋给相同主键一个序号,赋给同一个主键下的多条记录一个从一递增的序号
例如:
  
  item1 item2 name subject
  1 1 lily maths
  1 2 lily english
  1 3 lily chinese
  2 1 lucy maths
  2 2 lucy english


现有的数据位

  lily maths
  lily english
  lily chinese
  lucy maths
  lucy english


------解决方案--------------------
rank()函数试试
------解决方案--------------------
SQL code

insert into table (item1, item2, name, subject)
select tt.item1 , rank() over(partition by tt.rr order by tt.tml_type_cd,tt.tml_id) as item2, tt.name , tt.subject from (select dense_rank() over(order by t.name ) as item1,t.name,t.subject from table1 t ) tt;

------解决方案--------------------
探讨
SQL code

insert into table (item1, item2, name, subject)
select tt.item1 , rank() over(partition by tt.rr order by tt.tml_type_cd,tt.tml_id) as item2, tt.name , tt.subject from (select dense_rank(……