gpt4 book ai didi

MYSQL - 2个组合表之间的搜索条件

转载 作者:行者123 更新时间:2023-11-28 23:26:08 24 4
gpt4 key购买 nike

我想问一下

我有 2 个表,它们是:

表:一般库存

enter image description here

和表:Item_Master_List

enter image description here

现在我的目标是根据 ItemCode 将两个表组合起来,例如

...其中 GeneralInventory.ItemCode=Item_Master_List.ItemCode

类似的东西。现在我这样做了,这是我的完整代码

    Select GI.ItemCode,IML.Description,IML.StandardUOM,IML.StandardPrice 
from GeneralInventory GI,item_master_list IML where
GI.ItemCode = IML.ItemCode

这是输出

enter image description here

现在我的程序中有一些标准,它看起来像这样

enter image description here

这是我的问题。如何在我的 MYSQL 命令中应用搜索功能?我怎样才能搜索到正确的数据?使用组合列?我试过这个,但它会导致多个数据冗余

Select Distinct GI.ItemCode,IML.Description,IML.StandardUOM,IML.StandardPrice from 
GeneralInventory GI,item_master_list IML where GI.ItemCode = GI.ItemCode and
IML.ItemCode = '' or IML.Description = 'Baking Soda 454 g' or IML.StandardUOM = '';

enter image description here

附加问题

我还有一个名为 Table: StockAdjust 的表,这就是它的内容

enter image description here

现在我拥有的最好的代码就是这个

SELECT DISTINCT GI.ItemCode,
IML.Description,
IML.StandardUOM,
IML.StandardPrice
FROM GeneralInventory GI
INNER JOIN item_master_list IML
ON GI.ItemCode = IML.ItemCode
WHERE IML.ItemCode = 'My Data' OR
IML.Description = 'My Data' OR
IML.StandardUOM = 'My Data'

上面的代码将合并表 GeneralInventory GIitem_master_list IML,其中 GI.ItemCode = IML.ItemCode 和使用 ff 的过滤条件。 IML.ItemCode、IML.Description 和 IML.StandardUOM

现在我的问题是如何应用 NOT IN 命令?喜欢

以上代码.....AND GI.ItemCode NOT IN(在 StockAdjust 中选择 ItemCode)

我怎样才能在这里应用一个代码来执行上面的代码,并且它不包括 StockAdjust 中已有的数据;

最佳答案

我认为您在查询中感到困惑,因为您将表连接条件放入 WHERE 子句中,该子句还包含搜索逻辑。相反,在查询中使用显式连接语法:

SELECT DISTINCT GI.ItemCode,
IML.Description,
IML.StandardUOM,
IML.StandardPrice
FROM GeneralInventory GI
INNER JOIN item_master_list IML
ON GI.ItemCode = IML.ItemCode
WHERE (IML.ItemCode = '' AND
GI.ItemCode NOT IN (SELECT ItemCode FROM StockAdjust) OR
IML.Description = 'Baking Soda 454 g' OR
IML.StandardUOM = ''

关于MYSQL - 2个组合表之间的搜索条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39262683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com