繁体   English   中英

如何将第二个维度列添加到聚合指标

[英]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 BYSELECT相同的列,但 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM