[英]How to add a second dimension column to an aggregated metric
我有一個 SUM 指標和一個分組依據的維度。 我想顯示另一個維度,並且我知道第二個維度的值對於第一個維度中的所有對應值都是相等的。 (這意味着如果我按第一維度分組和按第二維度分組,我會得到相同的結果)。 我怎樣才能顯示第二個維度呢?
select
SUM(case
when (eventType like 'Add') then 1 else 0
end) as sum_uploads,
userId
from entry
group by userId
order by sum_uploads desc
期望的結果是如果我可以運行類似的東西(添加第三列):
select
SUM(case
when (eventType like 'Add') then 1 else 0
end) as sum_uploads,
userId, userType
from entry
group by userId
order by sum_uploads desc
我不知道該嘗試什么。
您通常GROUP BY
與SELECT
相同的列,但 arguments 設置函數的列除外。 即將列 userType 添加到GROUP BY
:
select
SUM(case when (eventType like 'Add') then 1 else 0 end) as sum_uploads,
userId, userType
from entry
group by userId, userType
order by sum_uploads desc
順便說一句,而不是LIKE
不使用任何通配符,我會做eventType = 'Add'
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.