码迷,mamicode.com
首页 > 其他好文 > 详细

AggregatingMergeTree & 物化视图

时间:2021-06-05 18:20:32      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:art   values   order   view   www   money   material   agg   string   


创建表

create table agg_source(              id UInt8,                         name String,                      city String,                      money UInt32                  ) engine=MergeTree()              partition by city                 order by id;

插入数据

insert into agg_source values  (1, ‘aa‘, ‘SD‘, 200),          (2, ‘bb‘, ‘SD‘, 200),          (3, ‘cc‘, ‘SH‘, 200),          (4, ‘dd‘, ‘BJ‘, 200),          (5, ‘ee‘, ‘SZ‘, 200),          (6, ‘ff‘, ‘BJ‘, 100),          (7, ‘gg‘, ‘HZ‘, 100),          (8, ‘ww‘, ‘WH‘, 100)

创建物化视图

create materialized view agg_view    engine = AggregatingMergeTree()      partition by city                    order by city                        populate                             as                                   select                                   city,                                uniqState(name) name,                sumState(money) money            from agg_source                      group by city;

查询

select                     city,                  uniqMerge(name),       sumMerge(money)    from agg_view          group by city;

转自 https://www.cnblogs.com/crazy-rabbit/p/14708579.html#_labelTop

AggregatingMergeTree & 物化视图

标签:art   values   order   view   www   money   material   agg   string   

原文地址:https://www.cnblogs.com/abc608088/p/14852283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!