创建所需的脚本

Creating required script

我的问题是关于 select 声明。我有一个名为 test1 的 table 及其中的值。这是我创建 table 和插入值的脚本:

create table test1(id number, pc number, pe number);
insert into test1 values(12,0,900); 
insert into test1 values(12,0,901);
insert into test1 values(12,0,902);
insert into test1 values(12,91,900);
insert into test1 values(12,0,1);
insert into test1 values(12,91,900); 
insert into test1 values(12,91,901); 
insert into test1 values(12,91,900);
insert into test1 values(12,91,5);
insert into test1 values(13,0,900);
insert into test1 values(12,0,20); 
insert into test1 values(12,1,1);
insert into test1 values(12,0,900);
insert into test1 values(13,91,900); 
insert into test1 values(13,91,901); 
insert into test1 values(13,91,902); 
insert into test1 values(13,0,902);
insert into test1 values(13,91,201); 
insert into test1 values(13,91,202);
insert into test1 values(13,91,20);
insert into test1 values(13,0,900);
insert into test1 values(13,0,900); 
commit;

我的问题是如何 select Id 来自 test1 table 的 pc 列仅包含 0 或 91 并且 pe 列仅包含 20, 201, 202 , 900, 901 或 902。所以 Id 就像 13.

这是给你的sql

select id from test1 where pc in (0,91) and pe in (20, 201, 202, 900, 901, 902);

只需检查满足行数是否等于 count(*):

select id
from test1
group by id
having 
   count(*) = count(case when pc in (0,91) and pe in (20, 201, 202, 900, 901, 902) then 1 end)
select A, B from(
    select decode(pc,0,91,id,0) A, decode(pe,20,201,202,900,901,902,id,0) B from test1
) where A <> B;

select distinct c from(select decode(id,12,0,13,13) c from(select a.id from test1 a,test1 b 其中 a.pc=b.pc 和 b.pe=a.pe 和 a.id=b.id) 其中 1=1) 其中 c=13;