首页 > 解决方案 > 如果列在 SQL 中有多个值,则不选择

问题描述

下表ORDER中,我不想选择customer_id具有=636 的值,并且希望在 SQL 查询order_type中显示所有没有“636”的 customer_id 。order_type

order_id         order_type       order_number     customer_id
----------       ----------       ------------    --------------
100              768              9900000011        2222
101              636              1021              2222
103              768              8800000022        3333
104              768              7700000033        4444

结果,我只需要 customer_id 列中的 3333 和 4444 个值。如果 order_type 列中存在 636,那么我必须省略 customer_id。

标签: sqloracle

解决方案


使用此查询

select customer_id
from `order`
where customer_id
NOT IN (select customer_id from order where order_type = 636))

推荐阅读