tsbs icon indicating copy to clipboard operation
tsbs copied to clipboard

tsbs_run_queries about Clickhouse SQL has a bug about double-groupby-xxx

Open cocobond opened this issue 7 months ago • 0 comments

From the readme document, we can see:

Image

So, if there are 100 devices, the data should be hoursnumber of devices, while 100devices and 12h, result rows that should be 10012 = 1200 rows.

But origin sql will make it be 100rows (because ANY INNER JOIN)

SELECT
            hour,
            hostname,
            mean_usage_user, mean_usage_system, mean_usage_idle, mean_usage_nice, mean_usage_iowait
        FROM
        (
            SELECT
                toStartOfHour(created_at) AS hour,
                tags_id AS id,
                avg(usage_user) AS mean_usage_user, avg(usage_system) AS mean_usage_system, avg(usage_idle) AS mean_usage_idle, avg(usage_nice) AS mean_usage_nice, avg(usage_iowait) AS mean_usage_iowait
            FROM cpu
            WHERE (created_at >= '2024-01-01 14:37:14') AND (created_at < '2024-01-02 02:37:14')
            GROUP BY
                hour,
                id
        ) AS cpu_avg
        ANY INNER JOIN tags USING (id)
        ORDER BY
            hour ASC,
            hostname

cocobond avatar May 21 '25 09:05 cocobond