我们想查询此表:
Row bucket action count
1 1407974 aaaaaa 15
2 1407974 bbbbbb 67
3 1407369 aaaaaa 89
4 1407369 bbbbbb 501
到这个输出:
Row bucket actionA actionB
1 1407974 15 67
3 1407369 89 501
使用google bigquery查询的最便宜的方法是什么?
答案 0 :(得分:2)
SELECT
bucket, MAX(actionA) actionA, MAX(actionB) actionB
FROM (
SELECT
bucket,
CASE WHEN REGEXP_MATCH(action, 'aaaaaa') THEN count END actionA,
CASE WHEN REGEXP_MATCH(action, 'bbbbbb') THEN count END actionB
FROM [tmp.a]
) GROUP BY bucket