我正在尝试制作一个 grafana 时间序列图表,显示 pihole 阻止的查询的百分比。我所做的查询如下,但结果肯定不正确,我认为这是因为我处理 where 子句的方式。
SELECT
timestamp as time,
100.0 * (SELECT COUNT( * ) as query_count FROM queries WHERE status IN (1, 4, 5, 6, 7, 8, 9, 10, 11, 15)) / COUNT( * ) as percentage
FROM
queries
GROUP BY
time;
我将其添加到 ypur 查询中:
Select
timestamp as time,
( 100.0 *
(
SELECT COUNT( * ) as query_count FROM queries WHERE status IN (1, 4, 5, 6, 7, 8, 9, 10, 11, 15)
) ) / (SELECT COUNT( * ) as query_count FROM queries) as percentage
FROM
queries
GROUP BY
time;
我在开始时添加选择,并在子查询上添加选择以进行计数