sql - 在 Oracle SQL 中选择带有子查询的查询
问题描述
这是我试图通过大量简化来实现的一个例子。
我有一张这样的桌子:
CREATE TABLE temp_pt
(
pt_key number PRIMARY KEY
, history VARCHAR(20)
, country VARCHAR(2)
, currency VARCHAR(3)
, settlementday VARCHAR(10)
);
这张表中有一些记录,说如下:
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(1, 'MATCH', 'GB', 'GBP', '2020-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(2, 'MATCH', 'GB', 'GBP', '2021-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(3, 'MATCH', 'GB', 'EUR', '2020-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(4, 'MATCH', 'GB', 'EUR', '2021-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(5, 'MATCH', 'GI', 'GBP', '2020-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(6, 'MATCH', 'GI', 'GBP', '2021-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(7, 'MATCH', 'GI', 'EUR', '2020-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(8, 'MATCH', 'GI', 'EUR', '2021-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(9, 'MATCH', 'NL', 'GBP', '2020-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(10, 'MATCH', 'NL', 'GBP', '2021-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(11, 'MATCH', 'NL', 'EUR', '2020-12-01');
insert into temp_pt(PT_KEY, history, country, currency, settlementday) values(12, 'MATCH', 'NL', 'EUR', '2021-12-01');
我需要结算日 > 2020-12-31 的所有记录,除了那些(货币是 GBP,国家是 GB 或 GI)。我怎么写这个?
解决方案
需要选择此表中货币为 GBP 的所有记录,但如果 country 为 GB 或 GI 则不需要。
这似乎是一个简单的where
子句:
select t.*
from temp_pt
where current = 'GBP' and country not in ('GB', 'GI')
推荐阅读
- apache-kafka - 如何使用空闲线程避免 Kafka Streams 应用程序中的事务过期
- sql-server - 潜在存储过程中批处理的替代方法(使用临时表)
- python-3.x - 在 Locust 中创建多个任务
- python - 如何在 matplotlib 中指定沿 x 轴打印多少刻度?
- mysql - MySQL 8.0 中具有动态表名的递归查询
- amazon-web-services - 适用于小数据的 AWS ETL 解决方案
- java - for循环无限运行
- python-3.x - 尝试修改列的值时出现熊猫类型错误
- python - 运行行为 BDD 测试时有关此错误根本原因的任何建议
- python - numpy 数组的 scipy.ndimage.interpolation 移位给出错误的结果 - 错误?