简体   繁体   English

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

[英]How to add a second dimension column to an aggregated metric

I have a SUM metric and a dimension I am grouping by.我有一个 SUM 指标和一个分组依据的维度。 I want to display another dimension, and I know for a fact that the values of the second dimension are equal for all corresponding values in the first dimension.我想显示另一个维度,并且我知道第二个维度的值对于第一个维度中的所有对应值都是相等的。 (meaning I would get the same results if I group by the first dimension and if I group by the second dimension). (这意味着如果我按第一维度分组和按第二维度分组,我会得到相同的结果)。 how can I display the second dimension as well?我怎样才能显示第二个维度呢?

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

the desired result would be if I could run something like that (with the addition of the third column):期望的结果是如果我可以运行类似的东西(添加第三列):

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

I don't know exactly what to try.我不知道该尝试什么。

You typically GROUP BY the same columns as you SELECT , except those who are arguments to set functions.您通常GROUP BYSELECT相同的列,但 arguments 设置函数的列除外 Ie add the column userType to the GROUP BY :即将列 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

BTW, instead of LIKE without using any wild-cards, I'd do eventType = 'Add' .顺便说一句,而不是LIKE不使用任何通配符,我会做eventType = 'Add'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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