[英]How to make a sub-query based on query results in SQL
我目前正在尝试查询我们的装配项目及其相应组件的列表。 我一直在用几种不同的方式尝试这个查询,这是我目前所处的位置(我得到的最接近的地方)
SELECT inv_mast.item_id AS [Item ID]
,inv_mast.item_desc AS [Item Description]
,IMC.item_id AS [Component Item ID]
FROM inv_mast
INNER JOIN assembly_line ON inv_mast.inv_mast_uid = assembly_line.inv_mast_uid
LEFT JOIN inv_mast IMC ON assembly_line.component_inv_mast_uid = inv_mast.inv_mast_uid
WHERE inv_mast.item_id = 'LFV-SV59Z-2ZGD-LOGO-L'
在“Assembly_line”表中有一个 Component_inv_mast_uid,我需要使用它来查询我们的 Item ID 的组件(inv_mast 连接到 inv_mast_uid 上的 assembly_line)
它应该导出如下内容:
LFV-SV59Z-2ZGD-LOGO-L (LFV-SV59Z-2ZGD-L)
LFV-SV59Z-2ZGD-LOGO-L(印刷费)
我忘了提及当前正在导出的内容。 当我运行此查询时,它提供的大多数信息都是正确的,但是“组件项 ID”列返回 Null,我不知道为什么。 到目前为止,我只有加入基本表的经验,所以子查询对我来说是非常新的。
尝试使用
WHERE inv_mast.item_id like 'LFV-SV59Z-2ZGD-LOGO-L%'
而不是='LFV-SV59Z-2ZGD-LOGO-L'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.