我有一个像这样的字符串:
'41,42,43,44,45,46,'
来自此查询:
SELECT
GROUP_CONCAT(lv
SEPARATOR ',') as Id
FROM
(SELECT
@pv:=(SELECT
GROUP_CONCAT(Id
SEPARATOR ',')
FROM
iot_zone
WHERE
FIND_IN_SET(id_zone, @pv)) AS lv
FROM
iot_zone
JOIN (SELECT @pv:=40) tmp) a;
我需要将此结果加入到以下查询中:
SELECT T.* FROM T, T2
WHERE T.Id = T2.Id
其中T2是具有GROUP_CONCAT
结果的表41
42
43
44
45
46
你能帮助我吗?
非常感谢
答案 0 :(得分:0)
尝试以下
CREATE TABLE T2(Id int);
INSERT T2(Id)VALUES(41),(42),(43);
SELECT *
FROM
(
SELECT '41,42,43,44,45,46,' Id
) T
JOIN T2 on CONCAT(',',T.Id) LIKE CONCAT('%,',T2.Id,',%')
我希望我能正确理解你的问题。
我找到了FIND_IN_SET
- SELECT WHERE IN with GROUP_CONCAT as input
我认为它会更有用
SELECT *
FROM
(
SELECT '41,42,43,44,45,46,' IdList
) T
JOIN T2 ON FIND_IN_SET(T2.Id,T.IdList)