当字符串'DebugData'包含数字时,我必须进行子选择。但在google big query中,我收到错误“在select子句中不允许Subselect”。任何帮助将不胜感激!!
%%sql --module Test2
DEFINE QUERY Test2
SELECT
HardwareId, DebugReason, DebugData,
CASE
WHEN lower(DebugData) LIKE 'ver%' THEN 'Verizon'
WHEN lower(DebugData) LIKE 'ro%' THEN 'Rogers'
WHEN REGEXP_MATCH(DebugData,'\\d+') THEN c.Network
(SELECT Network from [red-road-574:RawDebug.CarrierDetails] Where Mcc = SUBSTR(DebugData,0,3) and Mnc = SUBSTR(DebugData,4,7))
ELSE REGEXP_REPLACE(DebugData,'\\?',' ')
END
as ActualDebugData
FROM (TABLE_DATE_RANGE([bigdata:RawDebug.T], TIMESTAMP ('2016-05-15'),TIMESTAMP('2016-05-15')))
CROSS JOIN [bigdata:RawDebug.CarrierDetails] c
WHERE DebugReason = 50013
LIMIT 200
我尝试了这个,但这不起作用:
SELECT
DebugData,
CASE
WHEN lower(DebugData) LIKE 'jas%' THEN 'Jasper'
WHEN REGEXP_MATCH(DebugData,'\\d+') THEN c.Network
ELSE REGEXP_REPLACE(DebugData,'\\?',' ')
END
as ActualDebugData
FROM (TABLE_DATE_RANGE([bigdata:RawDebug.T],TIMESTAMP ('2016-05-15'),TIMESTAMP('2016-05-15')) d)
CROSS JOIN [bigdata:RawDebug.CarrierDetails] c
WHERE d.DebugReason = 50013 and c.Mcc = SUBSTR(DebugData,0,3)
LIMIT 200
答案 0 :(得分:1)
改为使用LEFT JOIN
。
SELECT
DebugData,
CASE
WHEN lower(DebugData) LIKE 'jas%' THEN 'Jasper'
WHEN REGEXP_MATCH(DebugData,'\\d+') THEN c.Network
ELSE REGEXP_REPLACE(DebugData,'\\?',' ')
END
as ActualDebugData
FROM (TABLE_DATE_RANGE([bigdata:RawDebug.T],TIMESTAMP ('2016-05-15'),TIMESTAMP('2016-05-15')) d)
LEFT JOIN [bigdata:RawDebug.CarrierDetails] c ON c.Mcc = SUBSTR(DebugData,0,3)
WHERE d.DebugReason = 50013
LIMIT 200
使用LEFT JOIN
可以让它从第一个表中返回与匹配条件不匹配的行。