如何在clickhouse中将具有相同列值的mysql行分组为一行?

3bygqnnd  于 2021-07-15  发布在  ClickHouse
关注(0)|答案(1)|浏览(555)

我在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
mlmc2os5

mlmc2os51#

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

clickhouse中的数据透视

相关问题