我有一个聚合了一些UNION ALL选择的子查询。在此之前,我准备了SELECT来创建交叉表并将其限制为20.我希望能够在主查询中限制它们之前检索子查询结果的总计数。这是为了尝试构建一个分页,它接收记录的总数,然后是特定的页面记录网格。在应用LIMIT(clickhouse)之前对子查询进行SELECT计数
样品查询:
SELECT
name,
sumIf(metric_value, metric_name = 'data') AS data,
sumif(....
FROM
(SELECT
name, metric_name, SUM(metric_value) as metric_value
FROM
(SELECT
name, 'data' AS metric_name, SUM(data) AS metric_value
FROM
table
WHERE
date > '2017-01-01 00:00:00'
GROUP BY
name
UNION ALL
SELECT
name, 'data' AS metric_name, SUM(data) AS metric_value
FROM
table2
WHERE
date > '2017-01-01 00:00:00'
GROUP BY
name
UNION ALL
SELECT
name, 'data' AS metric_name, SUM(data)