|
楼主 |
发表于 2011-10-31 12:09:35
|
显示全部楼层
Re:#求一sql语句,删除重复记
SQL code
CREATE TABLE STU
(
stu_number varchar(20),
stu_name varchar(20),
stu_age int
)
INSERT INTO STU
SELECT '110','张三',10 UNION all
SELECT '110','张三',10 UNION all
SELECT '111','李四',11 UNION all
SELECT '111','李四',11 UNION all
SELECT '112','王五',10
select * from STU
stu_number stu_name stu_age
-------------------- -------------------- -----------
110 张三 10
110 张三 10
111 李四 11
111 李四 11
112 王五 10
delete STU
from
(select row_number() over(partition by stu_number,stu_name,stu_age order by (select 0)) rn, * from STU) STU
where rn>1
select * from STU
stu_number stu_name stu_age
-------------------- -------------------- -----------
110 張三 10
111 李四 11
112 王五 10 |
|