我是靠谱客的博主 完美芝麻,最近开发中收集的这篇文章主要介绍ClickHouse支持row_number函数,相关的demo如下,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1,ck对窗口函数支持不是太好,只是有限的支持。

表结构如下:

CREATE TABLE warehouse.c_click_common_16_cls (`id` String, `app_version` Nullable(String), `guid` Nullable(String), `imei` Nullable(String), `mac` Nullable(String), `channel_id` Nullable(String), `tel_opr` Nullable(String), `phone_brand` Nullable(String), `phone_type` Nullable(String), `osversion` Nullable(String), `platform` Int32, `lang` Nullable(String), `session_id` Nullable(String), `client_time` Int64, `user_id` Nullable(String), `event_id` Nullable(String), `client_ip` Nullable(String), `net_type` Int32, `body_title` Nullable(String), `body_id` Nullable(String), `body_type` Nullable(String), `body_car_id` Nullable(String), `body_city_name` Nullable(String), `app_date` Int32, `create_time` Date, `body_index` Nullable(String)) ENGINE = Distributed(crm_4shards_1replicas, warehouse, c_click_common_16, rand())

 

2,业务数据分行:

select  versiontype,platform,date,
arrayJoin(arr_val)
--arrayJoin(row_number)
from (
select versiontype,platform,date,
groupArray(4)(uv) AS arr_val,
arrayEnumerate(4)(arr_val) as row_number
from (
    select 
    case when app_version>='3.0.0' then 'new'
          else 'old' end as versiontype,
          platform,
          toDate(client_time/1000) date,
          body_title, 
     count(distinct imei) uv
    from warehouse.c_click_common_16_cls
    where toDate(client_time/1000)='2020-06-22'
    and body_title not in('xxxx')
    group by versiontype,
          platform,
          toDate(client_time/1000),
          body_title
    order by uv desc) m
group by versiontype,platform,date
) c 

查询结果如下:

3,针对结果数据进行分行

select  versiontype,platform,date,
arrayJoin(arr_val)
--arrayJoin(row_number)
from (
select versiontype,platform,date,
groupArray(4)(uv) AS arr_val,
arrayEnumerate(4)(arr_val) as row_number
from (
    select 
    case when app_version>='3.0.0' then 'new'
          else 'old' end as versiontype,
          platform,
          toDate(client_time/1000) date,
          body_title, 
     count(distinct imei) uv
    from warehouse.c_click_common_16_cls
    where toDate(client_time/1000)='2020-06-22'
    and body_title not in('xxxx')
    group by versiontype,
          platform,
          toDate(client_time/1000),
          body_title
    order by uv desc) m
group by versiontype,platform,date
) c 

查询结果如下:

最后

以上就是完美芝麻为你收集整理的ClickHouse支持row_number函数,相关的demo如下的全部内容,希望文章能够帮你解决ClickHouse支持row_number函数,相关的demo如下所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(82)

评论列表共有 0 条评论

立即
投稿
返回
顶部