mysql - SELECT where not exists with another select 语句
问题描述
我在这里有这段代码:
select wms.product_code, WMS.barcode from(Select id,barcode,
concat('0',barcode,checkdigit) as zc from outerb) as outerb
join wms on outerb.zc = wms.barcode;
我需要根据上面的查询选择/查看所有不匹配的值。
这是我已经尝试过的:
SELECT * FROM wms where not exists (select wms.product_code, WMS.barcode
from(Select id,barcode, concat('0',barcode,checkdigit) as zc from outerb) as
outerb
join wms on outerb.zc = wms.barcode);
但是这个查询什么也不返回。该zc
表也是临时表。
使用 MySql 工作台
Table: outerb
Columns:
Id int(11) AI PK
Product_code varchar(255)
Brand varchar(255)
Product_desc varchar(255)
Size varchar(255)
Barcode varchar(255)
checkdigit varchar(255)
Table: wms
Columns:
Id int(11) AI PK
Product_code varchar(255)
Barcode varchar(255)
解决方案
这将为您提供在 OUTERB 中没有匹配的所有 WMS 行:
select *
from wms
where not exists
(
select null
from outerb o
where concat('0', o.barcode, o.checkdigit) = wms.barcode
);
或使用NOT IN
:
select *
from wms
where barcode not in (select concat('0', o.barcode, o.checkdigit) from outerb);
推荐阅读
- python - 使用 zipline 摄取 Quandl 缺乏数据
- java - 重构代码,以便使用此流管道
- oracle - 从给定字符串中提取子字符串,Oracle
- python - 在 Django 中自动更新个人资料图片
- java - 静态 Java 对象的最佳 Android 替代品
- javascript - 在递归数组中移动对象
- django - 更多外键如何在 django 中工作
- react-native - react-native:Flatlist的OnEndReached在滚动视图中不起作用
- kubernetes - Kubernetes - 使用 nginx-ingress 公开网站
- sitecore - 将 Sitecore 联系人从一个列表移动到另一个列表