如何对整数列执行 group_concat?
How to do group_concat with Integer columns?
此查询显示过去 2 周内一系列天数中 3 个端点的综合性能(使用某些优先级决定)。
select
date,
GROUP_CONCAT(endpoint, ', ') as endpoints, -- This works fine, since endpoint is string
GROUP_CONCAT(success, ', ') as endpoints_successes, -- This fails
(sum(success) / sum(attempts) * 100) as percentage
from
some_table
where
and datadate = from_timestamp(date_sub(now(), 14), 'yyyyMMdd')
and endpoint in (
select distinct endpoint
from some_table
order by some_priority desc
limit 2
)
group by date
order by date
为了在仪表板中显示,我需要使用 group_concat
之类的方法组合数据集的值。这似乎适用于 String
类型的列。
然而,当我想合并 success
字段的值进行显示时,它失败并出现以下错误:
No matching function with signature: group_concat(BIGINT, STRING)
我应该如何将 Int 转换为 String 以便在 group_concat
中使用,或者是否有另一种完全相同的方法?
先尝试将这些数值转换为 STRING
,然后再使用 GROUP_CONCAT
:
汇总它们
SELECT
date,
GROUP_CONCAT(endpoint, ', ') AS endpoints,
GROUP_CONCAT(CAST(success AS STRING), ', ') AS endpoints_successes, -- cast here
SUM(success) / SUM(attempts) * 100 AS percentage
FROM some_table
WHERE
datadate = FROM_TIMESTAMP(DATE_SUB(NOW(), 14), 'yyyyMMdd') AND
endpoint IN (SELECT endpoint FROM some_table ORDER BY some_priority DESC LIMIT 2)
GROUP BY date
ORDER BY date;
此查询显示过去 2 周内一系列天数中 3 个端点的综合性能(使用某些优先级决定)。
select
date,
GROUP_CONCAT(endpoint, ', ') as endpoints, -- This works fine, since endpoint is string
GROUP_CONCAT(success, ', ') as endpoints_successes, -- This fails
(sum(success) / sum(attempts) * 100) as percentage
from
some_table
where
and datadate = from_timestamp(date_sub(now(), 14), 'yyyyMMdd')
and endpoint in (
select distinct endpoint
from some_table
order by some_priority desc
limit 2
)
group by date
order by date
为了在仪表板中显示,我需要使用 group_concat
之类的方法组合数据集的值。这似乎适用于 String
类型的列。
然而,当我想合并 success
字段的值进行显示时,它失败并出现以下错误:
No matching function with signature: group_concat(BIGINT, STRING)
我应该如何将 Int 转换为 String 以便在 group_concat
中使用,或者是否有另一种完全相同的方法?
先尝试将这些数值转换为 STRING
,然后再使用 GROUP_CONCAT
:
SELECT
date,
GROUP_CONCAT(endpoint, ', ') AS endpoints,
GROUP_CONCAT(CAST(success AS STRING), ', ') AS endpoints_successes, -- cast here
SUM(success) / SUM(attempts) * 100 AS percentage
FROM some_table
WHERE
datadate = FROM_TIMESTAMP(DATE_SUB(NOW(), 14), 'yyyyMMdd') AND
endpoint IN (SELECT endpoint FROM some_table ORDER BY some_priority DESC LIMIT 2)
GROUP BY date
ORDER BY date;