[英]group_concat in subquery
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;
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 我尝试分配GROUP_CONCAT(DISTINCT tbl1.logid)的别名并将其放在IN()内部的值但仍然无法解决
the parent query returns something like 12,34,3,56 and that i want to use in the IN function 父查询返回类似12,34,3,56的内容,我想在IN函数中使用它
this not actually the whole case, but i just want to figure this out, 这实际上不是整个案例,但我只想弄明白这一点,
You cannot use the output of GROUP_CONCAT for IN() as it is returning a string. 您不能将GROUP_CONCAT的输出用于IN(),因为它返回一个字符串。 Use the result of a subquery for IN().
将子查询的结果用于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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.