2013-04-23 209 views

回答

4

的一種方式,這是用正則表達式提取物(see reference here):

SELECT 
    title, LENGTH(REGEXP_EXTRACT(title, r'^(.*)def.*')) + 1 AS location_of_fragment 
FROM 
    [publicdata:samples.wikipedia] 
WHERE 
    REGEXP_MATCH(title, r'^(.*)def.*') 
LIMIT 10; 

返回:

Row title location_of_fragment  
1 Austrian air defense 14 
2 Talk:Interface defeat 16 
3 High-definition television 6  
4 Talk:IAU definition of planet 10 
5 Wikipedia:Articles for deletion/Culture defines politics 41 
6 Wikipedia:WikiProject Spam/LinkReports/defenders.org 40 
7 Adenine phosphoribosyltransferase deficiency 35 
8 Stay-at-home defenceman 14 
9 Manganese deficiency (plant) 11 
10 High-definition television 6 
0

傳統SQL INSTR(str1,str2)函數「返回第一次出現字符串的基於1的索引」。所以這應該適合你。

https://cloud.google.com/bigquery/docs/reference/legacy-sql

+0

如果你正在尋找的標準配置SQL,然後STRPOS(字符串,字符串)「返回字符串內子第一次出現的1開始的索引。返回值爲0,子未找到」。 https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#strpos – 2018-01-10 21:00:07

相關問題