función de embudo de clickhouse

Ejemplo básico

Cree la siguiente tabla CREATE TABLE funnel.funnel_test ( uid String, eventid String, eventTime UInt64) ENGINE = MergeTree PARTITION BY (uid, eventTime) ORDER BY (uid, eventTime) SETTINGS index_granularity = 8192
con tres campos:
uid: id de usuario
eventid: id de evento
eventTime: tiempo de ocurrencia del evento (segundos)
Inserte los siguientes datos como datos de prueba:
uid1 event1 1551398404
uid1 event2 1551398406
uid1 event3 1551398408
uid2 event2 1551398412
uid2 event3 1551398415
uid3 event3 1551398410
uid3 event4 1551398413

1.select uid,windowFunnel(4)(toDateTime(eventTime),eventid = 'event2',eventid = 'event3') as funnel from funnel_test group by uid;
Cuando establecemos la ventana deslizante en 4 segundos y la cadena de condiciones es event2-> event3, el resultado de la consulta anterior es:
uid funnel
uid1 2
uid2 2
uid3 0
Veamos cómo obtuvo este resultado Sí, primero agregue y ordene todos los datos de acuerdo con uid (la ordenación se implementa en windowFunnel ) y obtenga:
uid1: (event1,1551398404) -> (event2,1551398406) -> (event3,1551398408)
uid2: (event2, 1551398412) -> (evento3,1551398415)
uid3: (evento3,1551398410) -> (evento4,1551398413)

En la cadena de condiciones después de la agregación y clasificación anteriores, solo uid1 y uid2 tienen una cadena de condiciones de event2-> event3, y la diferencia de tiempo es 2 (1551398408-1551398406) y 3 (1551398415-1551398412), que es más pequeña que la ventana deslizante 4, por lo que la condición se cumple , Entonces los resultados de uid1 y uid2 son 2 (event2, event3) y uid3 es 0 (no hay una cadena condicional que cumpla la condición)
2.  Si la ventana deslizante se cambia a 2

select uid,windowFunnel(2)(toDateTime(eventTime),eventid = 'event2',eventid = 'event3') as funnel from funnel_test group by uid;
  • 1

De la cadena de condiciones obtenida anteriormente, el resultado es
uid embudo
uid1 2
uid2 1
uid3 0
Por qué uid2 se convierte en 1, porque la diferencia de tiempo entre event3 y event2 en la cadena de condiciones de uid2 es 3, que es mayor que el tiempo de ventana deslizante 2, por lo que solo La primera condición event2 satisface la consulta, por lo que el resultado es 1.
3.  Si la ventana deslizante es 4, la cadena de condiciones se cambia a event3, event4,

select uid,windowFunnel(4)(toDateTime(eventTime),eventid = 'event3',eventid = 'event4') as funnel from funnel_test group by uid;
  • 1

Entonces el resultado de la consulta es
uid funnel
uid1 1
uid2 1
uid3 2
porque uid1 y uid2 solo tienen el evento 3 y ningún evento 4.
Y uid3 tiene tanto el evento3 como el evento4, y la diferencia de tiempo entre los dos eventos es menor que la ventana deslizante 4, por lo que el resultado de uid3 es 2.

2 caso 

El ingeniero de BI crea algunos enlaces de eventos en la página para contar el número de personas que han completado los pasos.

1 Ver los datos Analizar los atributos de los datos Prestar atención a los campos clave 
2 Los datos tienen un formato de almacenamiento especial jsonrow Importar los datos a la tabla CH para facilitar el procesamiento
3 Analizar si la función analizada por Json puede satisfacer las necesidades Analizar cada elemento de los datos de la fila Necesidad de
   analizar un determinado atributo para
   determinar un determinado ¿Existe este atributo
 ? 1) Java lee y analiza, convierte a CSV, escribe 
 2) El programa MR lee, analiza, convierte a CSV y escribe 
 3) La función json_tulpe en hive analiza jsonrow ---> Exportar datos CSV

4) También existe el análisis json correspondiente en clickhouse. Para revisar la colmena, usamos los siguientes pasos

Analice los datos en Hive y expórtelos más tarde, y luego importe los datos a clickhouse

2.1 Tabla de compilación de Hive para importar datos

create external table tb_log(
 content string 
 ) location "/data/log/" ;

2.2 Exportar datos a local

insert overwrite local directory '/data/log'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' 
select json_tuple(content,
'account',
'appId',
'appVersion',
'carrier',
'deviceId',
'deviceType',
'eventId',
'ip',
'latitude',
'longitude',
'netType',
'osName',
'osVersion',
'properties',
'releaseChannel',
'resolution',
'sessionId',
'timeStamp') as(
account
,appId
,appVersion
,carrier
,deviceId
,deviceType
,eventId
,ip
,latitude
,longitude
,netType
,osName
,osVersion
,properties
,releaseChannel
,resolution
,sessionId
,ctime) from tb_log limit 10 ;

2.3 Importar datos a CH

cat /data/log/000000_0  | clickhouse-client  -q  "insert into  demo.tb_log FORMAT  TSV"  
create table  tb_log(
account String,
appId String,
appVersion String
,carrier String
,deviceId String
,deviceType String
,eventId String
,ip String
,latitude Float64
,longitude Float64
,netType String
,osName String
,osVersion String
,properties String
,releaseChannel String
,resolution String
,sessionId String ,
ctime UInt64
)engine=MergeTree 
order by account;
┌─account──┬─appId───────────┬─appVersion─┬─carrier──┬─deviceId─────┬─deviceType─┬─eventId─────┬─ip─────────────┬──────────latitude─┬──────────longitude─┬─netType─┬─osName──┬─osVersion─┬─properties───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─releaseChannel─┬─resolution─┬─sessionId───┬─────────ctime─┐
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ productView │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"631","productId":"328","refType":"5","refUrl":"460","title":"vhI oUe cJx","url":"gGr/YOS","utm_campain":"11","utm_loctype":"1","utm_source":"10"} │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063129607 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ fetchCoupon │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"couponId":"17","pageId":"435"}                                                                                                                             │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063088656 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"15","adId":"9","adLocation":"7","pageId":"71"}                                                                                                 │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063152560 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ share       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"614","productId":"476","shareMethod":"微博","title":"wcR SJg iTl","url":"tbt/mWf"}                                                                │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063158158 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ fetchCoupon │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"couponId":"15","pageId":"207"}                                                                                                                             │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063070148 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adClick     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"12","adId":"3","adLocation":"9","pageId":"559"}                                                                                                │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063096000 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ share       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"44","productId":"204","shareMethod":"微博","title":"LEJ gOI yuu","url":"eZy/HJB"}                                                                 │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063103740 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"2","adId":"19","adLocation":"7","pageId":"379"}                                                                                                │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063170894 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ productView │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"534","productId":"539","refType":"4","refUrl":"140","title":"ZiR Lml Url","url":"PsE/VCX","utm_campain":"16","utm_loctype":"5","utm_source":"5"}  │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063142579 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ search      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"keywords":"xHKc sEm"}                                                                                                                                      │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063168398 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ share       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"113","productId":"79","shareMethod":"微信朋友圈","title":"pRB SLj oUf","url":"lmv/vHp"}                                                           │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063166808 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ submitOrder │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"refType":"3"}                                                                                                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063062810 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"12","adId":"14","adLocation":"1","pageId":"521"}                                                                                               │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063081092 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ thumbup     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"698","productId":"582","title":"OfI nCO ylw","url":"Aij/VLC"}                                                                                     │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063077158 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ thumbup     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"78","productId":"676","title":"lTB ndI dQA","url":"fxB/aZn"}                                                                                      │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063189203 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ share       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"449","productId":"454","shareMethod":"微博","title":"lzn ZSY GLx","url":"ZXv/Jut"}                                                                │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063090137 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"12","adId":"5","adLocation":"3","pageId":"151"}                                                                                                │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063119442 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ productView │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"570","productId":"308","refType":"5","refUrl":"65","title":"tXC rLN cgg","url":"NIE/ibu","utm_campain":"4","utm_loctype":"1","utm_source":"5"}    │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063108535 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adClick     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"5","adId":"16","adLocation":"8","pageId":"486"}                                                                                                │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063206149 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ fetchCoupon │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"couponId":"2","pageId":"660"}                                                                                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063132735 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ thumbup     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"599","productId":"331","title":"Ptg ZAq tyy","url":"Vef/HSS"}                                                                                     │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063149670 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ submitOrder │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"refType":"1"}                                                                                                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063145913 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ collect     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"696","productId":"956","title":"oFX OuO ytI","url":"xby/WXY"}                                                                                     │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063210664 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ login       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"account":"v8S9H"}                                                                                                                                          │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063156164 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ collect     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"151","productId":"29","title":"liP uLX ncg","url":"pZf/tGk"}                                                                                      │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063207335 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ pageView    │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"34","refUrl":"34","title":"EwS Frd Qie","url":"goe/TpQ","utm_campain":"14","utm_loctype":"4","utm_source":"5"}                                    │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063162634 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ pageView    │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"491","refUrl":"992","title":"VHz zdV rja","url":"NxJ/kOp","utm_campain":"10","utm_loctype":"1","utm_source":"10"}                                 │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063063921 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ login       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"account":"MtpZ2lV"}                                                                                                                                        │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063173567 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"20","adId":"16","adLocation":"8","pageId":"271"}                                                                                               │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063125282 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ fetchCoupon │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"couponId":"13","pageId":"559"}                                                                                                                             │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063184853 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ thumbup     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"791","productId":"142","title":"gfA rSM lkt","url":"fZR/mWe"}                                                                                     │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063067142 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ submitOrder │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"refType":"4"}                                                                                                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063182904 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ submitOrder │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"refType":"3"}                                                                                                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063072411 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"15","adId":"10","adLocation":"4","pageId":"422"}                                                                                               │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063196716 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ share       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"125","productId":"532","shareMethod":"微信朋友圈","title":"kvl XHj RAN","url":"plk/GnJ"}                                                          │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063087624 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ search      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"keywords":"qr fJU"}                                                                                                                                        │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063123212 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ pageView    │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"542","refUrl":"34","title":"rze xCE zoz","url":"Vue/QNQ","utm_campain":"9","utm_loctype":"5","utm_source":"5"}                                    │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063092729 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ thumbup     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"389","productId":"574","title":"Xzw bjX QrN","url":"LDT/onB"}                                                                                     │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063191736 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ search      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"keywords":"uwr Gzny"}                                                                                                                                      │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063098950 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ pageView    │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"882","refUrl":"41","title":"wqt aHs pLr","url":"KTP/wKk","utm_campain":"6","utm_loctype":"1","utm_source":"1"}                                    │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063116823 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"20","adId":"6","adLocation":"10","pageId":"169"}                                                                                               │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063112233 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ productView │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"368","productId":"545","refType":"5","refUrl":"526","title":"VJO noV aPt","url":"mro/Afs","utm_campain":"17","utm_loctype":"2","utm_source":"3"}  │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063213627 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ share       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"511","productId":"928","shareMethod":"qq空间","title":"XjT CJZ Vfe","url":"Ugi/knL"}                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063138700 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ adShow      │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"adCampain":"4","adId":"20","adLocation":"5","pageId":"108"}                                                                                                │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063137646 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ fetchCoupon │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"couponId":"15","pageId":"359"}                                                                                                                             │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063214780 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ collect     │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"294","productId":"918","title":"QEX TZf gii","url":"bKn/eqW"}                                                                                     │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063201466 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ share       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"pageId":"966","productId":"703","shareMethod":"qq空间","title":"wOp jee CRv","url":"KSk/CSQ"}                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063187536 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ login       │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"account":"csKUd83"}                                                                                                                                        │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063178018 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ fetchCoupon │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"couponId":"12","pageId":"620"}                                                                                                                             │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063085665 │
│ DxL36Dom │ cn.doitedu.app1 │ 2.2        │ 中国联通 │ 0HtfcnPofgoR │ REDMI-5    │ fetchCoupon │ 160.171.79.244 │ 34.21346724565028 │ 117.60034950493103 │ 4G      │ android │ 6.5       │ {"couponId":"2","pageId":"393"}                                                                                                                              │ 百度手机助手   │ 1024*768   │ meO4lXHYmx1 │ 1602063059899 │
└──────────┴─────────────────┴────────────┴──────────┴──────────────┴────────────┴─────────────┴────────────────┴───────────────────┴────────────────────┴─────────┴─────────┴───────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴────────────────┴────────────┴─────────────┴───────────────┘

Código

select
total ,
(o1+o2+o3+o4) as adShow,
(o2+o3+o4) as adClick,
(o3+o4) as productView,
(o4) as submitOrder
from
(select
count(1) as total ,
sum(if(cc=4 , 1 , 0)) as o4 ,
sum(if(cc=3 , 1 , 0)) as o3 ,
sum(if(cc=2 , 1 , 0)) as o2 ,
sum(if(cc=1 , 1 , 0)) as o1 
from
(select
deviceId ,
windowFunnel(3600)(
toDateTime(ctime) ,
eventId='adShow'  ,
eventId='adClick',
eventId='productView' ,
eventId='submitOrder'
) as cc
from
tb_log 
group by deviceId));

 

 

 

 

 

Supongo que te gusta

Origin blog.csdn.net/qq_37933018/article/details/109152046
Recomendado
Clasificación