【发布时间】:2023-03-27 02:19:01
【问题描述】:
我有一张如下表。
我想选择语言不为空的 spec_id。但是,当 spec_id 除了 null 之外没有其他值时,我也想选择具有 null 值的 spec_id。 例如。 Spec_id“170470”的语言为“EN”。我只想为此 spec_id 选择 Language is not null 的那一行。而 spec_id '170464' 只有 Null 值。所以我也想选择该行。
我已尝试使用以下查询,但它仅选择语言中 NOT NULL 的情况。
SELECT * from temp_value w1
where w1.NAC_ID = 2453
and w1.language is not null
or (w1.language is null and not exists (select spec_id from temp_value w2
where w2.nac_id = 2453
and spec_id in (select spec_id from temp_value
where nac_id = 2453 and language is not null))
and w1.nac_id = 2453);
【问题讨论】:
标签: sql select null oracle12c exists