簡體   English   中英

如何在 ClickHouse 中將具有相同列值的 mysql 行分組為一行?

[英]How to group mysql rows with same column value into one row in ClickHouse?

我在 ClickHouse 中使用這個查詢:

SELECT DISTINCT
  iap.EventId,
  iap.Id as Title,
  ole.RewardId,
  ole.RewardGain,
  if((ole.RewardType = 'Currency' and ole.RewardId = 'Cash'), ole.RewardGain, null) as Soft
FROM OpenLootboxEvent ole 
ANY LEFT OUTER JOIN InAppPurchaseEvent iap
ON ole.EventSourceId = iap.EventId
WHERE iap.Id in ('superHotDeal');

此查詢返回結果:

EventId  Title         RewardId  Gain  
---------------------------------------------------------------------
111      superHotDeal  m3        5    
111      superHotDeal  m14       13         
111      superHotDeal  m20       25         
111      superHotDeal  Cash      282            
111      superHotDeal  Talent    null   
111      superHotDeal  Hard      null  

每個“EventId”和“Title”都有 6 個含義,其中“RewardId”的值可以從“m1”到“m26”,它總是可以有“Cash”、“Talent”、“Hard”值。

如何檢索同一行中具有相同“EventId”和“Title”的所有行?

像這樣:

EventId  Title         man1  man1Cards   man2  man2Cards   man3  man3Cards  Cash  Talent  Hard                     
----------------------------------------------------------------------------------------------
111      superHotDeal  m3  5             m14   13          m20   25         282   null    null
select EventId, Title, groupArray(tuple(RewardId, RewardGain))
from (
SELECT DISTINCT
  iap.EventId EventId,
  iap.Id as Title,
  ole.RewardId RewardId,
  ole.RewardGain RewardGain,
  if((ole.RewardType = 'Currency' and ole.RewardId = 'Cash'), ole.RewardGain, null) as Soft
FROM OpenLootboxEvent ole 
ANY LEFT OUTER JOIN InAppPurchaseEvent iap
ON ole.EventSourceId = iap.EventId
WHERE iap.Id in ('superHotDeal'))
group by EventId, Title

Pivot 在 clickhouse

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM