子查询中的 group_concat [英] group_concat in subquery

查看:46
本文介绍了子查询中的 group_concat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select GROUP_CONCAT(DISTINCT tbl1.logid)  ,
(

    SELECT COUNT( DISTINCT tbl2.client_id ) 
    FROM tbl_client tbl2

    WHERE tbl2.con_id
    IN ( GROUP_CONCAT(DISTINCT tbl1.logid) ) 


) as PC2,

from tbl_table tbl1;

我尝试分配 GROUP_CONCAT(DISTINCT tbl1.logid) 的别名并将其放入 IN() 内的值中,但仍然无法解决

i try to assign an alias of GROUP_CONCAT(DISTINCT tbl1.logid) and place it in the value inside the IN() but still it doesn't work out

父查询返回类似 12,34,3,56 的内容并且我想在 IN 函数中使用

the parent query returns something like 12,34,3,56 and that i want to use in the IN function

这实际上不是整个情况,但我只是想弄清楚这一点,

this not actually the whole case, but i just want to figure this out,

推荐答案

您不能使用 GROUP_CONCAT 用于 IN() 因为它返回一个字符串.使用 IN() 的子查询结果.

You cannot use the output of GROUP_CONCAT for IN() as it is returning a string. Use the result of a subquery for IN().

select GROUP_CONCAT(DISTINCT tbl1.logid)  ,
(

SELECT COUNT( DISTINCT tbl2.client_id ) 
FROM tbl_client tbl2

WHERE tbl2.con_id
IN ( SELECT logid from tbl_table ) 


) 

as PC2,

from tbl_table tbl1;

这篇关于子查询中的 group_concat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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