是否有任何可能的方法将 group_concat 的结果放入 SQL 查询的 IN 条件中。
在网络主表中,我在 industryId 列中有逗号分隔的字段。 喜欢,
userId industryId
123 3831
123 2832,3832
123 3833
例子:
select group_concat(industryId order by cId SEPARATOR ',') from network_master where userId = 123
它给了我这种类型的输出 3831,2832,3832,3833 我使用上层查询得到了这种类型的输出,
userId industryId
123 3831,2832,3832,3833
现在我做了这件事,
select * from industry_master where industryId in (select group_concat(industryId order by cId SEPARATOR ',') from network_master where userId =123 group by userId);
在这个查询结果中,我只得到了 industryId=3831 的 details 输出。我没有得到其他 ID 输出。
我需要此查询中的所有 industryId 输出。我如何在 mysql 中实现这些。
如有任何帮助,我们将不胜感激。
最佳答案
我已经尝试过上述情况,但没有在我这边工作。我刚刚编辑了上面的答案并删除了 > 0 然后我可以看到你的预期输出。
你能试试下面的代码吗?
select * from industry_master where find_in_set(industryId, (select group_concat(industryId order by cId SEPARATOR ',')
from network_master where userId = 123 group by userId));
关于mysql - group_concat 结果在 IN 条件下不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49148152/