用户行为分析之漏斗分析

主体为人:


SELECT
        transform(level_index,[1, 2, 3],['t08_tracking_add_to_cart', 't01_trade_order_info', 't01_trade_refund_info_ext'], '其他') as event,  count(1)
FROM
        (
        SELECT uid, arrayWithConstant(level, 1) levels, arrayJoin(arrayEnumerate(levels)) level_index
        FROM
                (
                SELECT
                        uid,  windowFunnel(600)(create_time_time, event = 't08_tracking_add_to_cart', event = 't01_trade_order_info', event = 't01_trade_refund_info_ext') AS level
                FROM
                        (
                        select
                                *
                        from
                                (
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't08_tracking_add_to_cart' event FROM t08_tracking_add_to_cart WHERE os = 'ios'
                        UNION ALL
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't01_trade_order_info' event FROM t01_trade_order_info
                        UNION ALL
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't01_trade_refund_info_ext' event FROM t01_trade_refund_info_ext
                                )
                        where shop_cd = 'ANF0S01' and toDate(create_time_time) between '2023-02-01' and '2023-02-15'  --and uid in ('482377181', '327385228')
                        )
                GROUP BY uid  ) )
group by level_index
ORDER BY level_index

每一天

SELECT
        transform(level_index,[1, 2, 3],['t08_tracking_add_to_cart', 't01_trade_order_info', 't01_trade_refund_info_ext'], '其他') as event,  count(1), create_time
FROM
        (
        SELECT uid ,create_time, arrayWithConstant(level, 1) levels, arrayJoin(arrayEnumerate(levels)) level_index
        FROM
                (
                SELECT
                        uid, create_time,  windowFunnel(40)(create_time_time, event = 't08_tracking_add_to_cart', event = 't01_trade_order_info', event = 't01_trade_refund_info_ext') AS level
                FROM
                        (
                        select
                                *
                        from
                                (
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't08_tracking_add_to_cart' event FROM t08_tracking_add_to_cart WHERE os = 'ios'
                        UNION ALL
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't01_trade_order_info' event FROM t01_trade_order_info
                        UNION ALL
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't01_trade_refund_info_ext' event FROM t01_trade_refund_info_ext
                                )
                        where shop_cd = 'ANF0S01' and toDate(create_time_time) between '2023-02-01' and '2023-02-15' --and uid in ('482377181', '327385228')
                        )
                GROUP BY uid,create_time  ) )
group by level_index,create_time
ORDER BY create_time,level_index;

整体次数转化:


SELECT
        transform(level_index,[1, 2, 3],['t08_tracking_add_to_cart', 't01_trade_order_info', 't01_trade_refund_info_ext'], '其他') as event,  count(1)
FROM
        (
        SELECT uid, arrayWithConstant(level, 1) levels, arrayJoin(arrayEnumerate(levels)) level_index
        FROM
                (
                SELECT
                        uid,  windowFunnel(600)(create_time_time, event = 't08_tracking_add_to_cart', event = 't01_trade_order_info', event = 't01_trade_refund_info_ext') AS level
                FROM
                        (
                        select
                                *
                        from
                                (
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't08_tracking_add_to_cart' event FROM t08_tracking_add_to_cart WHERE os = 'ios'
                        UNION ALL
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't01_trade_order_info' event FROM t01_trade_order_info
                        UNION ALL
                                select uid, create_time_time, create_time, shop_cd, chan_shop_name, dt, 't01_trade_refund_info_ext' event FROM t01_trade_refund_info_ext
                                )
                        where shop_cd = 'ANF0S01' and toDate(create_time_time) between '2023-02-01' and '2023-02-15'  --and uid in ('482377181', '327385228')
                        )
                GROUP BY uid  ) )
group by level_index
ORDER BY level_index

这里有一个大坑:偶尔会报错:Pattern application proves too difficult, exceeding max iterations (1000000): While executing ConvertingAggregatedToChunksTransform (version 20.8.6.6 (official build))
太诡异了。排查了一天,去GitHub看,发现很早就有这个问题了。ClickHouse这种级别的数据库,理论上应该是早就解决了。最后发现是当计算每一天的t08_tracking_add_to_cart 到 t01_trade_refund_info_ext 转化时,如果某一天t08_tracking_add_to_cart 行为没有数据,会报这个错误。

你可能感兴趣的:(数学建模,clickhouse)