test1(id int,id int2 id int3)
值:
1,1,1,4
2,1,1,6
3,1,1,54,2,2,6
5,2,2,5
6,2,2,8
7,2,2,9
==============================
想读出其中的
1,1,1,4
4,2,2,6读取中间两列相同的数据记录组中的某一行记录!谢谢!
值:
1,1,1,4
2,1,1,6
3,1,1,54,2,2,6
5,2,2,5
6,2,2,8
7,2,2,9
==============================
想读出其中的
1,1,1,4
4,2,2,6读取中间两列相同的数据记录组中的某一行记录!谢谢!
解决方案 »
- Oracle不能通过localhost或者127.0.0.1访问数据库
- 关于简单的PL/SQL函数问题(十万火急)
- +++++++++++存储过程中怎么实现动态表明++++++++++++++++
- 自定义oracle初始化参数文件使用问题再提
- JInitiator 问题,客户端(WinXp)安装了JInitiator,XP升级sp2后,IE无法显示form,大家帮忙!
- Win2003上安装Oracle9是否有特别要注意的地方?
- 怎么测试游标中的值
- 并行会话数的问题
- 用system用户进行备份时,能不能不导出系统的那些表
- 怎样用一个表的结构建一个新的表
- 求高手帮忙写一条SQL,想了2天都没实现想要的结果。。。
- oci释放句柄的问题
create table a( id1 int ,id2 int ,id3 int , id4 int);select * from a;insert into a values (1,1,1,4);
insert into a values(2,1,1,6);
insert into a values(3,1,1,5);
insert into a values(4,2,2,6);
insert into a values(5,2,2,5);
insert into a values(6,2,2,8);
insert into a values(7,2,2,9);select id1,id2,id3,id4
from a
where id1 in ( select min(id1)
from a
where id2 = id3
group by id2);
-- 手头没有oracle数据,使用 sql2000 通过 ,没有特别的东西,oracle也肯定通过
--你的列名起的很诡异呀!完全看不懂~~~
select *
from
(select row_number() over(partition by col2,col3 order by col1) rn,a.* from test where a.col2=a.col3)
where rn=1
第二列和第三列不一定是相同的数据!谢谢!
请高手们再帮帮忙!谢谢啦!
你这不是自相矛盾啊?如果是指中间两列的组合重复,用1楼的语句.create table a( id1 int ,id2 int ,id3 int , id4 int);
insert into a values(1,1,1,4);
insert into a values(2,1,1,6);
insert into a values(3,1,1,5);
insert into a values(4,2,2,6);
insert into a values(5,2,2,5);
insert into a values(6,2,2,8);
insert into a values(7,2,2,9);select id1,id2,id3,id4 from a t
where id1 in (select min(id1) from a where id2 = t.id2 and id3 = t.id3 group by id2 , id3);drop table a /*
id1 id2 id3 id4
----------- ----------- ----------- -----------
1 1 1 4
4 2 2 6
*/
1 2 3 4
1 2 3 4
2 3 4 5
2 3 4 6
6 2 3 7
1 7 7 1
4 5 5 8
1 5 5 9
2 7 7 0
9 3 4 9
0 2 6 7已选择11行。SQL> select id1,id2,id3,id4 from
2 (select id1,id2,id3,id4,row_number() over(partition by id2,id3 order by id2,id3) as rn from test1)
3 where rn=2;
1 2 3 4
2 3 4 6
1 5 5 9
2 7 7 0SQL> select id1,id2,id3,id4 from
2 (select id1,id2,id3,id4,row_number() over(partition by id2,id3 order by id2,id3) as rn from test1)
3 where rn=3;
6 2 3 7
9 3 4 9SQL> select id1,id2,id3,id4 from
2 (select id1,id2,id3,id4,row_number() over(partition by id2,id3 order by id2,id3) as rn from test1)
3 where rn=1;
1 2 3 4
0 2 6 7
2 3 4 5
4 5 5 8
1 7 7 1
--楼主应该是要这样的吧?
select *
from
(select row_number() over(partition by col2,col3 order by col1) rn,a.* from test)
where rn=1
select *
from (select row_number() over(partition by id2, id3 order by id1) rn,a.*
from a)
where rn = 1 and id2 = id3rn = 1 这个1就代表你要取其中的哪一行。 取第一行就 rn = 1 第二行就rn = 2