sql - 创建所需的脚本
问题描述
我的问题是关于选择语句。我有一个名为test1的表和其中的值。这是我用于创建表和插入值的脚本:
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;
我的问题是如何从test1表中选择pc列仅包含0 或 91而pe列仅包含20、201、202、900、901 或 902的Id。所以ID就像13。
解决方案
只需检查满足行数是否等于 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)
推荐阅读
- javascript - Multi Stage BPF - 如何知道我正在转移到另一个实体?
- objective-c - 在 myproject-swift.h 中找不到接口声明
- django - Django表单未在模板中呈现输入字段
- postgresql - 如何更新postgresql中的jsonb列,它只是一个值数组,没有键
- mysql - 如何获取列数
- ios - iOS 中的 kCMTimeIndefinite 是什么?
- android - 如何在 viewpager 中添加片段和活动,以便片段出现在滑动时?
- c# - 如何修复异常“请求 System.Security.Permissions.EnvironmentPermission ... 类型的权限失败”
- javascript - 即使在使用 javascript 在 wordpress 中单击 Ok 后,如何停止进入下一个 POP 框?
- ios - iOS - 在后台模式下不扫描 BLE 外围设备