clickhouse sql記錄

1、新增字段

 ALTER TABLE dws.表名字  ADD  COLUMN 字段名字  Nullable(Float32) DEFAULT NULL

2逢唤、修改字段名稱(chēng)

ALTER TABLE dws.表名字  RENAME COLUMN 舊名字  TO 新名字

優(yōu)秀代碼記錄:
(1) 用戶留存代碼

with 
        14 as len, -101 as fill
        select
  
        arrayResize(arrayMap(x->x[2], arraySort(x->x, groupArray([period, impression/retention]))), len, fill) as days
from
        (
        select
                date, toInt16(period) as period, sum(impression) as impression,sum(retention) as retention,
                 sum(case when  period = '0' then cost else 0 end ) as cost, sum(case when  period = '0' then install_num else 0 end ) as install_num
        from
                dws.dws_overseas_new_users_data
        where
                date >= today()-8
                and country = 'US'
        group by
                date, period )
group by
        date

(2) 漏斗分析代碼

SELECT media_source AS media_source, funnel_sort AS funnel_sort, count(1) AS total_count
FROM (SELECT media_source,
             arraySort(x ->
                           -x, groupArray(count)) AS funnel_sort
      FROM (SELECT media_source, level_index, count(1) AS count
            FROM (SELECT media_source,
                         user_id                           AS user_id,
                         arrayJoin(arrayEnumerate(levels)) AS level_index,
                         arrayWithConstant(level, 1)       AS levels
                  FROM (SELECT media_source,
                               user_id,
                               windowFunnel(86400)(parseDateTimeBestEffort(event_time), event_name = 'bf_enter_success',
                                            event_name = 'bf_ad_show', event_name = 'StayTimePerMinute',
                                            event_name = 'RewardVideoShowSuccess') AS level
                        FROM (SELECT date         AS date,
                                     country      AS country,
                                     app_name     AS app_name,
                                     app_version  AS app_version,
                                     media_source AS media_source,
                                     user_id      AS user_id,
                                     event_name   AS event_name,
                                     app_id       AS app_id,
                                     event_time   AS event_time
                              FROM ods.ods_appsflyer_event
                              WHERE 1 = 1
                                AND date BETWEEN '2020-10-01' AND '2020-10-18'
                                AND media_source in ('google', 'facebook', 'applovin', 'Apple Search Ads')
                                AND app_name like ('%%Build%%')
                                AND app_id = ('APAGQ4DANBZMYZTK')
                              LIMIT 100000 OFFSET 0)
                        WHERE 1 = 1
                        GROUP BY media_source, user_id)
                  WHERE 1 = 1)
            WHERE 1 = 1
            GROUP BY media_source, level_index)
      WHERE 1 = 1
      GROUP BY media_source
      LIMIT 1000 OFFSET 0)
WHERE 1 = 1
GROUP BY media_source, funnel_sort
SELECT media_source AS media_source, funnel_sort AS funnel_sort, count(1) AS total_count
FROM (SELECT media_source,
             arraySort(x ->-x, groupArray(count)) AS funnel_sort
      FROM (SELECT media_source, level_index, count(1) AS count
            FROM (SELECT media_source,
                         user_id                           AS user_id,
                         arrayJoin(arrayEnumerate(levels)) AS level_index,
                         arrayWithConstant(level, 1)       AS levels
                  FROM (SELECT media_source,
                               user_id,
                               windowFunnel(1468800)(parseDateTimeBestEffort(event_time),
                                            event_name = 'bf_enter_success', event_name = 'bf_ad_show',
                                            event_name = 'StayTimePerMinute',
                                            event_name = 'RewardVideoShowSuccess') AS level
                        FROM (SELECT date         AS date,
                                     country      AS country,
                                     app_name     AS app_name,
                                     app_version  AS app_version,
                                     media_source AS media_source,
                                     user_id      AS user_id,
                                     event_name   AS event_name,
                                     app_id       AS app_id,
                                     event_time   AS event_time
                              FROM ods.ods_appsflyer_event
                              WHERE 1 = 1
                                AND date BETWEEN '2020-10-01' AND '2020-10-18'
                                AND app_id = ('APAGQ4DANBZMYZTK'))
                        WHERE 1 = 1
                        GROUP BY media_source, user_id)
                  WHERE 1 = 1)
            WHERE 1 = 1
            GROUP BY media_source, level_index)
      WHERE 1 = 1
      GROUP BY media_source)
WHERE 1 = 1
GROUP BY media_source, funnel_sort




--unique_user+oneday--
SELECT media_source AS media_source, funnel_sort AS funnel_sort, count(1) AS total_count
FROM (SELECT media_source,
             arraySort(x ->
                           -x, groupArray(count)) AS funnel_sort
      FROM (SELECT media_source, level_index, count(1) AS count
            FROM (SELECT media_source,
                         user_id                           AS user_id,
                         arrayJoin(arrayEnumerate(levels)) AS level_index,
                         arrayWithConstant(level, 1)       AS levels
                  FROM (SELECT media_source,
                               user_id,
                               windowFunnel(86400)(parseDateTimeBestEffort(event_time), event_name = 'bf_enter_success',
                                            event_name = 'bf_ad_show', event_name = 'StayTimePerMinute',
                                            event_name = 'RewardVideoShowSuccess') AS level
                        FROM (SELECT date         AS date,
                                     country      AS country,
                                     app_name     AS app_name,
                                     app_version  AS app_version,
                                     media_source AS media_source,
                                     user_id      AS user_id,
                                     event_name   AS event_name,
                                     app_id       AS app_id,
                                     event_time   AS event_time
                              FROM ods.ods_appsflyer_event
                              WHERE 1 = 1
                                AND date BETWEEN '2020-10-01' AND '2020-10-18'
                                AND app_id = ('APAGQ4DANBZMYZTK'))
                        WHERE 1 = 1
                        GROUP BY media_source, user_id)
                  WHERE 1 = 1)
            WHERE 1 = 1
            GROUP BY media_source, level_index)
      WHERE 1 = 1
      GROUP BY media_source)
WHERE 1 = 1
GROUP BY media_source, funnel_sort
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末槐雾,一起剝皮案震驚了整個(gè)濱河市豌熄,隨后出現(xiàn)的幾起案子齐邦,更是在濱河造成了極大的恐慌演侯,老刑警劉巖炕吸,帶你破解...
    沈念sama閱讀 206,968評(píng)論 6 482
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件伐憾,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡赫模,警方通過(guò)查閱死者的電腦和手機(jī)树肃,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,601評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)瀑罗,“玉大人胸嘴,你說(shuō)我怎么就攤上這事≌都溃” “怎么了劣像?”我有些...
    開(kāi)封第一講書(shū)人閱讀 153,220評(píng)論 0 344
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)停忿。 經(jīng)常有香客問(wèn)我驾讲,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 55,416評(píng)論 1 279
  • 正文 為了忘掉前任吮铭,我火速辦了婚禮时迫,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘谓晌。我一直安慰自己掠拳,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,425評(píng)論 5 374
  • 文/花漫 我一把揭開(kāi)白布纸肉。 她就那樣靜靜地躺著溺欧,像睡著了一般。 火紅的嫁衣襯著肌膚如雪柏肪。 梳的紋絲不亂的頭發(fā)上姐刁,一...
    開(kāi)封第一講書(shū)人閱讀 49,144評(píng)論 1 285
  • 那天,我揣著相機(jī)與錄音烦味,去河邊找鬼聂使。 笑死,一個(gè)胖子當(dāng)著我的面吹牛谬俄,可吹牛的內(nèi)容都是我干的柏靶。 我是一名探鬼主播,決...
    沈念sama閱讀 38,432評(píng)論 3 401
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼溃论,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼屎蜓!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起钥勋,我...
    開(kāi)封第一講書(shū)人閱讀 37,088評(píng)論 0 261
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤炬转,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后笔诵,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體返吻,經(jīng)...
    沈念sama閱讀 43,586評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,028評(píng)論 2 325
  • 正文 我和宋清朗相戀三年乎婿,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了测僵。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,137評(píng)論 1 334
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡谢翎,死狀恐怖捍靠,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情森逮,我是刑警寧澤榨婆,帶...
    沈念sama閱讀 33,783評(píng)論 4 324
  • 正文 年R本政府宣布,位于F島的核電站褒侧,受9級(jí)特大地震影響良风,放射性物質(zhì)發(fā)生泄漏谊迄。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,343評(píng)論 3 307
  • 文/蒙蒙 一烟央、第九天 我趴在偏房一處隱蔽的房頂上張望统诺。 院中可真熱鬧,春花似錦疑俭、人聲如沸粮呢。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,333評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)啄寡。三九已至,卻和暖如春哩照,著一層夾襖步出監(jiān)牢的瞬間挺物,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 31,559評(píng)論 1 262
  • 我被黑心中介騙來(lái)泰國(guó)打工飘弧, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留姻乓,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,595評(píng)論 2 355
  • 正文 我出身青樓眯牧,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親赖草。 傳聞我的和親對(duì)象是個(gè)殘疾皇子学少,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,901評(píng)論 2 345

推薦閱讀更多精彩內(nèi)容

  • 這是第一次數(shù)據(jù)分析的實(shí)踐,選擇了比較經(jīng)典的淘寶用戶行為數(shù)據(jù)集秧骑,考慮到這個(gè)數(shù)據(jù)集比較大版确,能夠了解一下各種程序?qū)讉€(gè)G...
    pobabyq閱讀 1,262評(píng)論 0 2
  • 一、數(shù)據(jù)埋點(diǎn)是什么 數(shù)據(jù)埋點(diǎn)是數(shù)據(jù)產(chǎn)品經(jīng)理乎折、數(shù)據(jù)運(yùn)營(yíng)以及數(shù)據(jù)分析師绒疗,基于業(yè)務(wù)需求(例如:CPC點(diǎn)擊付費(fèi)廣告中統(tǒng)計(jì)每...
    嗯哼嗯閱讀 25,852評(píng)論 0 51
  • 目錄:1、項(xiàng)目背景2骂澄、數(shù)據(jù)導(dǎo)入與認(rèn)識(shí)3吓蘑、數(shù)據(jù)清洗4、數(shù)據(jù)分析5坟冲、結(jié)論與建議 一磨镶、項(xiàng)目背景 移動(dòng)互聯(lián)網(wǎng)企業(yè)從粗放式到...
    jinghenggl閱讀 846評(píng)論 0 17
  • https://www.cnblogs.com/vame1/p/5776808.html 比方說(shuō)在查詢id是50的...
    小浪崇禮閱讀 290評(píng)論 0 0
  • sql 注入 1.盲注 (沒(méi)有回顯)2.顯錯(cuò)注入3.報(bào)錯(cuò)注入 顯錯(cuò)注入-聯(lián)合查詢(Mysql數(shù)據(jù)庫(kù))的基本流程 顯...
    Caeser_CC閱讀 435評(píng)論 0 2