group_concat结果在IN条件下不起作用 [英] group_concat result not work in IN condition

查看:910
本文介绍了group_concat结果在IN条件下不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何可能的方法可以将group_concat的结果置于SQL查询的IN条件中.

Is there any possible way to put result of group_concat in IN condition of SQL query.

在网络主表中,我在industryId列中用逗号分隔了各个字段. 喜欢,

Here in network master table i have comma separated fields in industryId column. Like,

userId     industryId
123        3831
123        2832,3832
123        3833

示例:

从中选择group_concat(cId SEPARATOR','的工业ID顺序) network_master,其中userId = 123

select group_concat(industryId order by cId SEPARATOR ',') from network_master where userId = 123

它给了我这种类型的输出3831,2832,3832,3833 我使用上层查询获得了这种类型的输出,

and it gives me this type of output 3831,2832,3832,3833 I got this type of output using upper query,

userId      industryId
123         3831,2832,3832,3833

现在我做了这件事,

从industry_master中选择*,其中industryId在(选择 group_concat(工业ID由cID SEPARATOR','排序) network_master,其中userId = 123按userId分组);

select * from industry_master where industryId in (select group_concat(industryId order by cId SEPARATOR ',') from network_master where userId =123 group by userId);

在此查询结果中,我仅获得了行业ID = 3831的详细信息输出.我没有得到其他Ids输出.

In this query result, I got details output of industryId=3831 only. I did not get other Ids output.

我需要此查询中的所有industryId输出.我如何在 mysql 中实现这些目标.

I need all the industryId output in this query. How to i achieve this things in mysql.

任何帮助将不胜感激.

推荐答案

我已经尝试过上述情况,但没有帮助我.我刚刚在答案上方进行了编辑,并删除了> 0,然后可以看到您的预期输出.

I have tried above case but not working on my side. I just edited above answer and removed > 0 then I can see your expected output.

您可以尝试以下代码吗?

Can you try below code?

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)); 

这篇关于group_concat结果在IN条件下不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆