sql - 如果列在 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。
解决方案
使用此查询
select customer_id
from `order`
where customer_id
NOT IN (select customer_id from order where order_type = 636))
推荐阅读
- android - 我被困在 gradle 错误中好几天了。我不知道如何解决这个问题。我在互联网上的任何地方都找不到解决方案
- ffmpeg - 如何将看似 NV21 rtsp 流转换为普通 YUV420 rtmp 流?
- node.js - Webpack 开发服务器未重新加载
- kotlin - 记录 Kotlin 代码:如何创建表?
- opengl - openGL - 批量渲染 - 对象矩阵/等更新
- javascript - 运行 Three.js 演示时遇到的硬件问题
- angular - 如何使用 Firebase 和延迟加载正确注销和导航
- java - 改造和 gson 错误:java.lang.IllegalStateException:预期 BEGIN_OBJECT 但在第 1 行第 1 列路径 $
- go - 从扫描仪转换为 io.Reader 的惯用方式
- mysql - 使用节点 js 中的 where 子句和 express API 选择查询会引发错误