测试数据:
create table PRICE
(
ID VARCHAR2(10),
PRICE NUMBER,
SYSID VARCHAR2(10)
);
insert into price (ID, PRICE, SYSID)
values ('10', 1000, '1');
insert into price (ID, PRICE, SYSID)
values ('10', 1000, '2');
insert into price (ID, PRICE, SYSID)
values ('20', 2000, '3');
insert into price (ID, PRICE, SYSID)
values ('20', 2500, '4');
insert into price (ID, PRICE, SYSID)
values ('30', 1000, '5');
insert into price (ID, PRICE, SYSID)
values ('30', 1000, '6');
insert into price (ID, PRICE, SYSID)
values ('30', 1500, '7');
insert into price (ID, PRICE, SYSID)
values ('40', 1000, '8');
insert into price (ID, PRICE, SYSID)
values ('40', 1000, '9');
insert into price (ID, PRICE, SYSID)
values ('40', 1500, '10');
insert into price (ID, PRICE, SYSID)
values ('40', 1500, '11');
insert into price (ID, PRICE, SYSID)
values ('50', 2000, '12');
insert into price (ID, PRICE, SYSID)
values ('50', 2500, '13');
insert into price (ID, PRICE, SYSID)
values ('50', 3000, '14');
commit;
SQL> select * from price;
ID PRICE SYSID
---------- ---------- ----------
10 1000 1
10 1000 2
20 2000 3
20 2500 4
30 1000 5
30 1000 6
30 1500 7
40 1000 8
40 1000 9
40 1500 10
40 1500 11
50 2000 12
50 2500 13
50 3000 14
14 rows selected
我想筛选出来的是这些数据:
ID PRICE SYSID
---------- ---------- ----------
20 2000 3
20 2500 4
30 1000 6(或者5)
30 1500 7
40 1000 9(或者8)
40 1500 11(或者10)
50 2000 12
50 2500 13
50 3000 14
9 rows selected
即所有ID相同,RPICE不相同,且PRICE不重复的记录,如:
ID PRICE SYSID
---------- ---------- ----------
30 1000 5
30 1000 6
30 1500 7
则选出SYSID为6、7的记录,或者5、7的记录。即在PRICE重复的记录中,任取一个出来。
请教sql写法。