Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql BigQuery模糊匹配联接或使用范围_Sql_Google Bigquery - Fatal编程技术网

Sql BigQuery模糊匹配联接或使用范围

Sql BigQuery模糊匹配联接或使用范围,sql,google-bigquery,Sql,Google Bigquery,在大查询中,联接中是否有方法使用模糊匹配,或者可能使用正则表达式跨一系列值进行匹配 例如,我有以下查询,其中持续时间值可能相差+/-30,因此如果callhistory.duration=268,则它将与calltracking.duration=292匹配,后者在指定的238到298范围内 select calltracking.date, calltracking.calling_phone_number, calltracking.duration, callhistory.row_da

在大查询中,联接中是否有方法使用模糊匹配,或者可能使用正则表达式跨一系列值进行匹配

例如,我有以下查询,其中持续时间值可能相差+/-30,因此如果callhistory.duration=268,则它将与calltracking.duration=292匹配,后者在指定的238到298范围内

select 
calltracking.date,
calltracking.calling_phone_number,
calltracking.duration,
callhistory.row_date,
callhistory.callid,
callhistory.calling_pty,
callhistory.duration,
calltracking.start_time_utc,
callhistory.segstart_utc


from

(SELECT 
cast(date(start_time_local) as string) as date,
calling_phone_number,
start_time_utc,
duration,
utm_medium,
utm_source
FROM [xxx:calltracking.calls]) calltracking

left join 

(select 
 *
 FROM [xxx:datamart.callhistory]) callhistory

on (callhistory.calling_pty = calltracking.calling_phone_number) and 
(callhistory.row_date = calltracking.date) and (callhistory.duration = 
calltracking.duration)

下面是BigQuery标准SQL的简化示例

标准SQL 使用'xxx.calltracking.calls'作为 选择1 id,292持续时间 ,`xxx:datamart.callhistory`AS 选择2 id,268持续时间 选择 t、 工业贸易署, t、 持续时间, h、 我藏起来了, h、 持续时间 来自`xxx.calltracking.calls`t 左连接`xxx:datamart.callhistory`h 在t.duration上,在h.duration-30和h.duration+30之间 注意:这不适用于BigQuery legacySQL,它看起来像是您在问题中使用的