我想知道是否可以在BigQuery中对记录进行分类。
例如;
number - site - visits
1-A-10
2-B-20
我想要使用站点A和B并创建一个组呼“汽车”。有人可以告诉我这是怎么做的吗?
答案 0 :(得分:2)
根据您对问题的评论,以下是我能想到的最佳方法 希望这是你要求的
SELECT
CASE
WHEN site IN ('A', 'B')
THEN 'Cars'
ELSE 'Others'
END AS category,
SUM(visits) AS visits
FROM
(SELECT 1 AS number, 'A' AS site, 10 AS visits),
(SELECT 2 AS number, 'B' AS site, 20 AS visits),
(SELECT 3 AS number, 'C' AS site, 50 AS visits)
GROUP BY 1
添加了CASE WHEN声明
的示例CASE
WHEN (Medium = "A" and source = "facebook.com" ) THEN 'Social'
WHEN (Medium = "B" and source = "facebook.com" ) THEN 'PaidSocial'
END as Category