去除重复记录Sql

duan17 2004-12-22 04:05:15
id flag name
1 send a
1 send b
1 send c
1 rece a
1 rece b
2 rece d

要显示的结果
1 send a
1 rece a
2 rece d

就是先按flag分组,然后去除id 列重复的
...全文
180 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyi8903 2004-12-23
  • 打赏
  • 举报
回复
这种情况.我想sqlserver也不能用distinct来实现.distinct出来的结果是不正确的.
它的用途只是以flag为主的列的各种组合.
我想sqlserver也不例外
lynx 2004-12-23
  • 打赏
  • 举报
回复
try this one:
select id,flag,name from (
select row_number() over (partition by id,flag order by name) rn ,my_test.*
from my_test )
where rn=1;
chentony 2004-12-23
  • 打赏
  • 举报
回复
SELECT id,flag,name
FROM table_name a
WHERE name = (SELECT c
FROM table_name
WHERE id = a.id AND flag = a.flag and rownum = 1 )
chentony 2004-12-23
  • 打赏
  • 举报
回复
select a,b,c
from aa a
where c = (select c from aa where a = a.a and b = a.b and rownum = 1 )
etheltim 2004-12-22
  • 打赏
  • 举报
回复
利用rowid
子陌红尘 2004-12-22
  • 打赏
  • 举报
回复
select
id ,
flag ,
max(name) as name
from

group by
id, flag
order by
id, flag
ORARichard 2004-12-22
  • 打赏
  • 举报
回复
to delphi_dcs(delphi人生)

ORACLE当然支持DISTINCT
不过你试试你的想法,看看能不能实现楼主的要求
delphi_dcs 2004-12-22
  • 打赏
  • 举报
回复
不会吧,怎么比sqlserver差那么多,distinct就可以了,看来oracle听罗嗦的
ORARichard 2004-12-22
  • 打赏
  • 举报
回复
select a.* from 表 a,
(
select min(rowid) no from 表 group by id,flag
) b
where a.rowid=b.no;
liuchunjp 2004-12-22
  • 打赏
  • 举报
回复
http://dev.csdn.net/develop/article/56/article/50/50484.shtm
Ineed123 2004-12-22
  • 打赏
  • 举报
回复
select a.* from table1 a where rowid>(select min(rowid) from table1 b where a.id=b.id and a.flag=b.flag)

17,377

社区成员

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

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