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

行转列例子

时间:2021-04-30 12:18:08      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:--   string   creat   nbsp   tree   into   engine   sum   tab   

create table test.t_20210429
(
app    String,
cnt Nullable(UInt32),
per Nullable(UInt32)
)
ENGINE=MergeTree()
order by app;

insert into test.t_20210429 values(‘a‘,100,200),(‘a‘,50,123),(‘b‘,1,1);
-------------------------------------------------------------------------------------------------------------
SELECT
    c1,c2
FROM 
(
    SELECT groupArray([cnt, per])[1] AS arr_1,[‘cc1‘, ‘cc2‘] AS arr_2
    FROM 
    (
        SELECT sum(cnt) AS cnt,sum(per) AS per
        FROM test.t_20210429
        WHERE app = ‘a‘
        GROUP BY app
    ) AS A
) AS B
ARRAY JOIN
    arr_1 AS c1,
    arr_2 AS c2
 ;

  

create table test.t_20210429(app    String,cnt Nullable(UInt32),per Nullable(UInt32))ENGINE=MergeTree()order by app;
insert into test.t_20210429 values(‘a‘,100,200),(‘a‘,50,123),(‘b‘,1,1);
SELECT    c1,c2FROM (    SELECT groupArray([cnt, per])[1] AS arr_1,[‘cc1‘, ‘cc2‘] AS arr_2    FROM     (        SELECT sum(cnt) AS cnt,sum(per) AS per        FROM test.t_20210429        WHERE app = ‘a‘        GROUP BY app    ) AS A) AS BARRAY JOIN    arr_1 AS c1,    arr_2 AS c2 ;

行转列例子

标签:--   string   creat   nbsp   tree   into   engine   sum   tab   

原文地址:https://www.cnblogs.com/muyue123/p/14719308.html

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