Mysql 子查询 IN 子句按 JSON 值查找

Mysql subquery IN clause Find by JSON Value

我有两个 table。一个是 product_details,另一个是大小。 每个产品都有多个尺寸。
我必须为每个产品设置一组尺寸。(如 100、125、150)。
但我已经在 product_details table 中将尺寸记录保存为 JSON 值(例如 ["1","2","8"])。
当我尝试使用 IN 子句和子查询获取记录时,我无法获取记录。 检查此 link:click here sqlfiddle

SELECT po_det.po_det_size as json_str, 
REPLACE(REPLACE(REPLACE(po_det.po_det_size, '[',''),']',''),'"','')) str,
(SELECT GROUP_CONCAT(size.size_name)
 FROM tbl_product_size size
 WHERE size.size_id IN (str)
) AS sizes
FROM tbl_purchase_order_details po_det

请帮我拿记录。

您不能为此使用 in。您可以使用 find_in_set():

where find_in_set(size.size_id, str) > 0

我认为您不能在子查询中使用列别名,所以这可能是另一个问题:

where find_in_set(size.size_id, REPLACE(REPLACE(REPLACE(po_det.po_det_size, '[',''),']',''),'"',''))) > 0