ClickHouse 实时数据去重final+group by
生活随笔
收集整理的這篇文章主要介紹了
ClickHouse 实时数据去重final+group by
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
通過實(shí)踐,最后發(fā)現(xiàn)argMax +group by 是最優(yōu)的,因?yàn)槭褂胒inale 運(yùn)行效率非常慢 。,下面的知識(shí)點(diǎn)可以不看了
實(shí)時(shí)數(shù)據(jù)使用final 最為保險(xiǎn)。
實(shí)時(shí)數(shù)據(jù)求和用final + group by 最為保險(xiǎn)
一、實(shí)時(shí)數(shù)據(jù)獲取最新訂單狀態(tài)并去重
1. 使用final (推薦)
去重并取最新的數(shù)據(jù)
select order_number --訂單號(hào) ,id --產(chǎn)品ID ,cnt--產(chǎn)品數(shù)量 ,price--產(chǎn)品當(dāng)時(shí)價(jià)格 from a final where no='1234567'2. 使用group by
--數(shù)量共4 產(chǎn)品65 2個(gè) 產(chǎn)品66 2個(gè) select order_number --訂單號(hào) ,id --產(chǎn)品ID ,cnt--產(chǎn)品數(shù)量 ,price--產(chǎn)品當(dāng)時(shí)價(jià)格 from a where no='1234567' group by order_number --訂單號(hào) ,id --產(chǎn)品ID ,cnt--產(chǎn)品數(shù)量 ,price --產(chǎn)品當(dāng)時(shí)價(jià)格3. 使用argMax() (不可取)
去重了相同數(shù)量不同產(chǎn)品id 的數(shù)據(jù),不準(zhǔn)確
--此處只顯示一個(gè) 2 selectorder_number --訂單號(hào) ,argMax(id,loaddate) id --產(chǎn)品ID ,argMax(cnt,loaddate) cnt--產(chǎn)品數(shù)量 ,argMax(price,loaddate) price--產(chǎn)品當(dāng)時(shí)價(jià)格 from a where no='1234567' group by order_number --訂單號(hào)二、實(shí)時(shí)數(shù)據(jù)金額求和獲取最新訂單狀態(tài)并去重使用final +group by
此處訂單重復(fù),需要去重后再匯總
select order_number --訂單號(hào) ,amt --訂單金額 from b where order_number ='123'1. 使用final+group by (推薦)
selectorder_number ,sum(amt) from b final where order_number ='123' group by order_number ;2. 只使用group by (不可取)
selectorder_number ,sum(amt) from b where order_number ='123' group by order_number ;總結(jié)
以上是生活随笔為你收集整理的ClickHouse 实时数据去重final+group by的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 综合评价法之秩和比法(RSR)
- 下一篇: bigemap功能介绍,视频教程