日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ClickHouse 实时数据去重final+group by

發(fā)布時間:2023/12/14 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。