[英]count not working inside group_concat Mysql
I am trying to concat count of id and 1 inside group_concat. 我正在尝试在group_concat中合并id和1的计数。 Below is my query.
以下是我的查询。
MYSQL: MYSQL:
SELECT
months.name AS NAME,
CONCAT(
'[',
GROUP_CONCAT(
CONCAT(
'[\"',
COUNT(p_c_n_details.JPN_ID),
'\",',
1,
']'
)
),
']'
) AS DATA
FROM
p_c_n_details
INNER JOIN in_e_s_s__p_c_ns RIGHT OUTER JOIN months ON months.id =
MONTH(p_c_n_details.created_at) AND p_c_n_details.type IN('Process Change',
'Design Change') AND p_c_n_details.JPN_ID =
in_e_s_s__p_c_ns.juniperinternalpcnid AND p_c_n_details.created_at >=
last_day(NOW()) + INTERVAL 1 DAY - INTERVAL 3 MONTH
WHERE
months.name IN(
MONTHNAME(
DATE_SUB(CURDATE(), INTERVAL 0 MONTH)),
MONTHNAME(
DATE_SUB(CURDATE(), INTERVAL 1 MONTH)),
MONTHNAME(
DATE_SUB(CURDATE(), INTERVAL 2 MONTH))
)
GROUP BY
months.id
Expected Output: 预期产量:
Name | DATA
-------------------------
July [20,1]
August [33,1]
Table months contains month names.
But I am getting error #1111 - Invalid use of group function.
但是我收到错误
#1111 - Invalid use of group function.
I tried this link mysql group_concat with a count inside? 我试过这个链接mysql group_concat里面有一个计数吗? but I am facing error when using in my query.
但在查询中使用时遇到错误。
This is a guess. 这是一个猜测。
Try: 尝试:
SELECT months.name AS NAME,
CONCAT('{',COUNT(p_c_n_details.JPN_ID),',1}' AS DATA
in place of the SELECT you now have. 代替您现在拥有的SELECT。
Your example result doesn't show a need for GROUP_CONCAT()
. 您的示例结果不显示需要
GROUP_CONCAT()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.