有表 a
序号 编号 类别 值
====================
1 1001 1 abc
1 1001 2 def
1 1001 3 val
2 1001 1 cad
2 1001 2 cap
2 1001 3 oop
3 2001 1 aaa
3 2001 2 add
3 2001 3 7yr
4 2001 1 443
4 2001 2 400
4 2001 3 50f如何得到如下结果(所有不同"编号"且类别为"2"的每一第一条记录,序号可以不要)
序号 编号 类别 值
====================
1 1001 2 def
3 2001 2 add
等待中...
序号 编号 类别 值
====================
1 1001 1 abc
1 1001 2 def
1 1001 3 val
2 1001 1 cad
2 1001 2 cap
2 1001 3 oop
3 2001 1 aaa
3 2001 2 add
3 2001 3 7yr
4 2001 1 443
4 2001 2 400
4 2001 3 50f如何得到如下结果(所有不同"编号"且类别为"2"的每一第一条记录,序号可以不要)
序号 编号 类别 值
====================
1 1001 2 def
3 2001 2 add
等待中...
解决方案 »
- Java调用存储过程的事务问题(任务紧急,望高手解决)
- 回滚段文件丢失,重建失败,该如何?
- 两个月没解决的问题,请各位感兴趣的朋友进来看看,只要问题能解决,分数没有上限!
- 删除系统权限的问题
- 请问可以在WINDOWS平台上管理UNIX上的ORACLE数据库服务端吗?
- 如何授予用户代理权限??
- 谁有 pl/sql developer 5.0 的注册号??(可用就加分)
- ORA-01652: unable to extend temp segment by 128 in tablespace TEMP
- 我想取出数据表中第三条纪录后的所有纪录(包括第三条)
- 求HP-UX双机热备资料,安装配置方面的!
- sql 语句
- oracle中设计数据库的时候,数据库名字、表名字、列名字都是怎么命名的?
SELECT 序号, 编号, 类别 , 值 FROM
(select row_number() over(partition by 编号 order by 类别) rn,A.* FROM A)
WHERE RN=1
insert into test select '1','1001','1','abc' from dual;
insert into test select '1','1001','2','def' from dual;
insert into test select '1','1001','3','val' from dual;
insert into test select '2','1001','1','cad' from dual;
insert into test select '2','1001','2','cap' from dual;
insert into test select '2','1001','3','oop' from dual;
insert into test select '3','2001','1','aaa' from dual;
insert into test select '3','2001','2','add' from dual;
insert into test select '3','2001','3','7yr' from dual;
insert into test select '4','2001','1','443' from dual;
insert into test select '4','2001','2','400' from dual;
insert into test select '4','2001','3','50f' from dual;
--测试
select * from(
select a.*,row_number()over(partition by 编号 order by 序号) as rn from test a) where rn=1;drop table test;--
/*序号 编号 类别 值 RN
1 1001 1 abc 1
3 2001 1 aaa 1*/
2 from (select 序号,
3 编号,
4 类别,
5 值,
6 row_number() over(partition by 编号 order by rowid) rn
7 from a
8 where 类别 = 2)
9 where rn = 1;
序号 编号 类别 值
-------------------- -------------------- -------------------- --------------------
1 1001 2 def
3 2001 2 add