这个SQL怎么样写

wangzhibing_3366 2010-10-27 05:11:23
有一个表A(a,b,c,d,e)记录有:
a1,b1,c1,d1,e1
a2,b1,c1,d1,e1
a3,b1,c1,d1,e2
a4,b2,c1,d1,e3
a5,b2,c1,d1,e3
a6,b2,c1,d1,e3

将b,c,d,e 相同的记录去掉。怎么样写
...全文
163 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
whh_bigsea 2010-11-16
  • 打赏
  • 举报
回复
都很厉害啊
Todd_Zhang 2010-11-16
  • 打赏
  • 举报
回复
学习中。。。
zhao1024cong112 2010-11-16
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zhuomingwang 的回复:]
SQL code
--把两条都去掉
select b,c,d,e from (
select b,c,d,e,count(a) rn
from A
group by b,c,d,e
)
where rn=1;
[/Quote]

不错!
zyprd 2010-11-16
  • 打赏
  • 举报
回复
delete from A t1 where
exists(select 1 from A t2 where t1.b = t2.b and t1.c = t2.c and t1.d = t2.d
and t1.e = t2.e and t1.a <> t2.a)
Todd_Zhang 2010-11-16
  • 打赏
  • 举报
回复
学习。。。
youshang444 2010-10-28
  • 打赏
  • 举报
回复
delete from A where a=
( select a from(
select a,b,c,d,e,count()over(partition by b,c,d,e) tot from A) B
where B.tot>=2
)

  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhou925290547 的回复:]
(select a,b,c,d row_number()over(partition by b,c,d order by a) 这个是什么意思啊 可以解释一下么?
[/Quote]select deptno,ename,row_number() over(partition by deptno order by ename) rn
from emp
把这个拿去运行下就知道了
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhou925290547 的回复:]
(select a,b,c,d row_number()over(partition by b,c,d order by a) 这个是什么意思啊 可以解释一下么?
[/Quote]select deptno,ename,row_number() over(partition by deptno order by ename) rn
from emp
把这个拿去运行下就知道了
心中的彩虹 2010-10-27
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhou925290547 的回复:]
(select a,b,c,d row_number()over(partition by b,c,d order by a) 这个是什么意思啊 可以解释一下么?
[/Quote]
分析函数 按b,c,d分组 然后按a排序 给这些定好的记录加个序号
a b c d
1 2 2 2
2 2 2 2
3 1 1 1
3 1 1 1
2 3 3 3

--结果这样
a b c d row_number()over(partition by b,c,d order by a) rn
1 2 2 2 1
2 2 2 2 2
3 1 1 1 1
5 1 1 1 2
2 3 3 3 1

orachow 2010-10-27
  • 打赏
  • 举报
回复
(select a,b,c,d row_number()over(partition by b,c,d order by a) 这个是什么意思啊 可以解释一下么?
  • 打赏
  • 举报
回复
--把两条都去掉
select b,c,d,e from (
select b,c,d,e,count(a) rn
from A
group by b,c,d,e
)
where rn=1;
心中的彩虹 2010-10-27
  • 打赏
  • 举报
回复
[Quote=引用楼主 wangzhibing_3366 的回复:]
有一个表A(a,b,c,d,e)记录有:
a1,b1,c1,d1,e1
a2,b1,c1,d1,e1
a3,b1,c1,d1,e2
a4,b2,c1,d1,e3
a5,b2,c1,d1,e3
a6,b2,c1,d1,e3

将b,c,d,e 相同的记录去掉。怎么样写
[/Quote]
select *
from tb where rowid in(select max(rowid) from tb group by b,c,d,e)
  • 打赏
  • 举报
回复
a1,b1,c1,d1,e1
a2,b1,c1,d1,e1
比如说这里条吧,你说的去掉是把两条都去掉呢,还是去掉其中的一天啊?
gelyon 2010-10-27
  • 打赏
  • 举报
回复

select a,b,c,d,e from (
select a,b,c,d,e,row_number()over(partition by b,c,d,e order by a) rn
from A
)
where rn=1;
jwwyqs 2010-10-27
  • 打赏
  • 举报
回复
相同的a怎么留啊

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧