combine only works on aggregate columns that belong to continuous views.
创建CONTINUOUS
CREATE CONTINUOUS VIEW v AS SELECT g::integer, AVG(x::integer) FROM stream GROUP BY g; CREATE CONTINUOUS VIEW
插入数据
INSERT INTO stream (g, x) VALUES (0, 10), (0, 10), (0, 10), (0, 10), (0, 10); INSERT INTO stream (g, x) VALUES (1, 20);
查询结果
pipeline=# SELECT * FROM v; g | avg ---+--------------------- 0 | 10.0000000000000000 1 | 20.0000000000000000 (2 rows)
pipeline=# SELECT avg(avg) FROM v; avg --------------------- 15.0000000000000000 (1 row)
使用Combine查询
pipeline=# SELECT combine(avg) FROM v; combine --------------------- 11.6666666666666667 (1 row)
直接对表表v求平均值,只会对对CQL结果进行再次求平均值。
如果拿Combine,那么会对总的6条数据来进行求平均值。
时间: 2024-11-10 21:36:40