4 colums
get_nth_smallest_value <- function(n) {
unique(sort(x))[n]
}
get_nth_smallest_value(2)
#[1] 6
get_nth_smallest_value(3)
#[1] 7
我需要计算用户在UserA列或UserB列中出现的次数
按UserA colum组不是succifient我需要计算john从UserA和UserB cols总共出现的次数
预期产出
| day of year | year | user A | user B |
1 1 john ron
2 1 ron john
1 2 john kyle
答案 0 :(得分:4)
您似乎想要union all
select user, count(*) counts from
(
select [user A] as user from table t
union all
select [user B] as user from table t
)a
group by user
答案 1 :(得分:1)
您可以编写如下查询: -
select user, sum(cnt) total
from
(select userA as user, count(*) cnt from table group by userA
UNION ALL
select userB as user, count(*) cnt from table group by userB
) a11
group by user