INSERT table2 ( table1Id , Table1Value ) SELECT table1id , value FROM table1 GROUP BY table1id , value
insert into table2(table1Id,Table1Value) select min(id) as id,value from table1 group by value
insert into table2(table1Id,Table1Value) select max(id) as id,value from table1 group by value
table2中没数据的话2、3L的方法可以解决,有数据的话还需要在插入前再比较一次
2楼的可以,用分组,下面的我用的是rownumber分组,思想差不多。 insert into table2(table1id,table1value) select id,value from ( select id,value,ROW_NUMBER() over (partition by value order by id) as rownum from table1 ) as t where rownum<2
( table1Id ,
Table1Value
)
SELECT table1id ,
value
FROM table1
GROUP BY table1id ,
value
select min(id) as id,value from
table1 group by value
insert into table2(table1Id,Table1Value)
select max(id) as id,value from
table1 group by value
insert into table2(table1id,table1value)
select id,value from
(
select id,value,ROW_NUMBER() over (partition by value order by id) as rownum from table1
) as t
where rownum<2