我非常新的BigQuery中的平台,我想采取以下字符串SOCKETIOEXCEPTION##APS.COM, NULLPOINTEREXCEPTION##RSJAVA.COM, CLASSCASTEEXCEPTION##MPS.COM
而得到这个结果:SOCKETIOEXCEPTION, NULLPOINTEREXCEPTION, CLASSCASTEEXCEPTION
之前##
字符我想从给定的字符串分开,然后我想按数量排在像SOCKETIOEXCEPTION, NULLPOINTEREXCEPTION, CLASSCASTEEXCEPTION
上述标签可用
示例数据库的详细信息
我怎样写这个查询?
下面是BigQuery的SQL标准
#standardSQL
SELECT SPLIT(line, '##')[OFFSET(0)] type, COUNT(1) cnt
FROM `project.dataset.table`
GROUP BY type
您可以测试,用样本数据上面从你的问题如下面的例子中玩
#standardSQL
WITH `project.dataset.table` AS (
SELECT 'SOCKETIOEXCEPTION##111' line UNION ALL
SELECT 'SOCKETIOEXCEPTION##222' UNION ALL
SELECT 'SOCKETIOEXCEPTION##333' UNION ALL
SELECT 'NULLPOINTEREXCEPTION##444' UNION ALL
SELECT 'NULLPOINTEREXCEPTION##555' UNION ALL
SELECT 'CLASSCASTEEXCEPTION##666' UNION ALL
SELECT 'CLASSCASTEEXCEPTION##777' UNION ALL
SELECT 'CLASSCASTEEXCEPTION##888'
)
SELECT SPLIT(line, '##')[OFFSET(0)] type, COUNT(1) cnt
FROM `project.dataset.table`
GROUP BY type
有结果
Row type cnt
1 SOCKETIOEXCEPTION 3
2 NULLPOINTEREXCEPTION 2
3 CLASSCASTEEXCEPTION 3