蚊子有多少颗牙齿,月光下的凤尾竹串词,斗鱼影院
-- 任意的测试表
create table test_delete(
name varchar(10),
value int
);
go
-- 张三100 与 王五80 是有重复的
insert into test_delete
select '张三', 100
union all select '张三', 100
union all select '李四', 80
union all select '王五', 80
union all select '王五', 80
union all select '赵六', 90
union all select '赵六', 70
go
-- 测试检索数据
select
row_number() over (partition by name, value order by (select 1) ) as no,
name,
value
from
test_delete
no name value
-------------------- ---------- -----------
1 李四 80
1 王五 80
2 王五 80
1 张三 100
2 张三 100
1 赵六 70
1 赵六 90
--创建视图
create view tmp_view as
select
row_number() over (partition by name, value order by (select 1) ) as no,
name,
value
from
test_delete
--删除数据
1> delete from tmp_view where no != 1
2> go
(2 行受影响)
-- 核对结果
1> www.jb51.net
2> select * from test_delete;
3> go
name value
---------- -----------
张三 100
李四 80
王五 80
赵六 90
赵六 70
(5 行受影响)
作者 tearsmo
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
sql某个日期是当年的第几周
/* *周一作为一周的开始 *当年的1月1号所在的周算作第一周 */ CREATE function GetWeekIndexFirstDate ( @...
[阅读全文]
-
-
数据库SQL---范式
1、数据冗余导致的问题:冗余存储、更新异常、插入异常、删除异常。 2、函数依赖:一种完整性约束。 在关系模式r(R)中,α属于R,β属于R。 1)α函数...
[阅读全文]
-
-
数据库SQL---查询
1、查询所有列 select *from emp;--*表示所有的,from emp表示从emp表中查询。 2、查询指定列 select empno,e...
[阅读全文]
-
-
-
-
-
网友评论