ClickHouse 实时数据去重final+group by
生活随笔
收集整理的這篇文章主要介紹了
ClickHouse 实时数据去重final+group by
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
通過實踐,最后發(fā)現(xiàn)argMax +group by 是最優(yōu)的,因為使用finale 運行效率非常慢 。,下面的知識點可以不看了
實時數(shù)據(jù)使用final 最為保險。
實時數(shù)據(jù)求和用final + group by 最為保險
一、實時數(shù)據(jù)獲取最新訂單狀態(tài)并去重
1. 使用final (推薦)
去重并取最新的數(shù)據(jù)
select order_number --訂單號 ,id --產(chǎn)品ID ,cnt--產(chǎn)品數(shù)量 ,price--產(chǎn)品當(dāng)時價格 from a final where no='1234567'2. 使用group by
--數(shù)量共4 產(chǎn)品65 2個 產(chǎn)品66 2個 select order_number --訂單號 ,id --產(chǎn)品ID ,cnt--產(chǎn)品數(shù)量 ,price--產(chǎn)品當(dāng)時價格 from a where no='1234567' group by order_number --訂單號 ,id --產(chǎn)品ID ,cnt--產(chǎn)品數(shù)量 ,price --產(chǎn)品當(dāng)時價格3. 使用argMax() (不可取)
去重了相同數(shù)量不同產(chǎn)品id 的數(shù)據(jù),不準(zhǔn)確
--此處只顯示一個 2 selectorder_number --訂單號 ,argMax(id,loaddate) id --產(chǎn)品ID ,argMax(cnt,loaddate) cnt--產(chǎn)品數(shù)量 ,argMax(price,loaddate) price--產(chǎn)品當(dāng)時價格 from a where no='1234567' group by order_number --訂單號二、實時數(shù)據(jù)金額求和獲取最新訂單狀態(tài)并去重使用final +group by
此處訂單重復(fù),需要去重后再匯總
select order_number --訂單號 ,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功能介绍,视频教程