mysql - group_concat 结果在 IN 条件下不起作用

标签 mysql

是否有任何可能的方法将 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/

相关文章:

sql - mysql 中的多重连接

mysql - 忽略符号的 SQL 查询

php - mysql建表失败

c++ - 如何在 Ubuntu 16.04 中安装 MySql Connector/C++

java - Netbeans 的 Hibernate Unicode;为什么在db中保存为 "?????"

mysql - 从 MySql 中的一列中提取多个值

mysql - 使用codeigniter创建数据库表

php - 如果内部数组中有匹配项,则获取外部数组的索引

mysql - GROUP_BY、MAX() 和 only_full_group_by

mysql - MySQL 中的动态连接