我該如何完成這項工作?SQL與子查詢相似
select * from item where item_name like '%' || (select equipment_type from equipment_type group by equipment_type) || '%'
內部子查詢返回像'的'測試「另一個」字符串列表,我想選擇的項目表,其中ITEM_NAME類似於子查詢返回值的所有項目。我需要有通配符。
是否有替代方案,我可以使用通配符,但使用IN sql命令呢?
我該如何完成這項工作?SQL與子查詢相似
select * from item where item_name like '%' || (select equipment_type from equipment_type group by equipment_type) || '%'
內部子查詢返回像'的'測試「另一個」字符串列表,我想選擇的項目表,其中ITEM_NAME類似於子查詢返回值的所有項目。我需要有通配符。
是否有替代方案,我可以使用通配符,但使用IN sql命令呢?
您可以使用INNER JOIN
:
SELECT I.*
FROM item I
INNER JOIN (SELECT equipment_type
FROM equipment_type
GROUP BY equipment_type) E
ON I.item_name LIKE '%' || E.equipment_type || '%'
ahhh不錯,我會試試這個,讓你知道盡快。 ty –
如果你不想擔心重複並不在乎哪一個相匹配,然後切換到使用exists
:
select i.*
from item i
where exists (select 1
from equipment_type
where i.item_name like '%'||equipment_type||'%'
)
oohhhh這個看起來不錯!我會盡力讓你知道 –
別你有ID做這個? – TechBytes
@TechBytes你是什麼意思? –
@TechBytes我明確指出,我有一個我想比較item_name的字符串列表。 –