流分析:Inner Join 两个子查询
Posted
技术标签:
【中文标题】流分析:Inner Join 两个子查询【英文标题】:Stream Analytics: Inner Join two subquery 【发布时间】:2018-02-06 15:20:53 【问题描述】:我在流分析中使用了两个子查询,以便可以运行两个 AzureML 函数。
WITH subquery as (
SELECT
id as id,
username as username,
try_cast(startTime as datetime) as startTime,
try_cast(endTime as datetime) as endTime,
AC as AC, FM as FM, UC as UC,
DL as DL, DS as DS, DP as DP,
LB as LB, ASTV as ASTV, MSTV as MSTV,
ALTV as ALTV, MLTV as MLTV, Width as Width,
Min as Min, Max as Max, Nmax as Nmax,
Nzeros as Nzeros, Mode as Mode, Mean as Mean,
Median as Median, Variance as Variance, Tendency as Tendency,
rms,fmed,fpeak,sample_entropy,
EventProcessedUtcTime as EventProcessedUtcTime,
Distress(AC,FM,UC,DL,DS,DP,1,LB,ASTV,MSTV,ALTV,MLTV,
Width,Min,Max,Nmax,Nzeros,Mode,Mean,Median,Variance,
Tendency,1,1,1,1,1,1,1,1,1,1,1,1) as resultFHR
FROM
iot
),
subquery2 as (
SELECT
id as id,
try_cast(startTime as datetime) as startTime,
try_cast(endTime as datetime) as endTime,
AC as AC, FM as FM, UC as UC,
DL as DL, DS as DS, DP as DP,
LB as LB, ASTV as ASTV, MSTV as MSTV,
ALTV as ALTV, MLTV as MLTV, Width as Width,
Min as Min, Max as Max, Nmax as Nmax,
Nzeros as Nzeros, Mode as Mode, Mean as Mean,
Median as Median, Variance as Variance, Tendency as Tendency,
rms,fmed,fpeak,sample_entropy,
EventProcessedUtcTime as EventProcessedUtcTime,
Labour("",1,1,1,"",rms,fmed,fpeak,sample_entropy,"","") as resultUC
FROM
iot
)
SELECT
id as id,
username as username,
startTime as startTime,
endTime as endTime,
AC as AC, FM as FM, UC as UC,
DL as DL, DS as DS, DP as DP,
LB as LB, ASTV as ASTV, MSTV as MSTV,
ALTV as ALTV, MLTV as MLTV, Width as Width,
Min as Min, Max as Max, Nmax as Nmax,
Nzeros as Nzeros, Mode as Mode, Mean as Mean,
Median as Median, Variance as Variance, Tendency as Tendency,
EventProcessedUtcTime as EventProcessedUtcTime,
resultFHR.[classes] as distress,
resultFHR.[probabilities] as distressProbability,
resultUC.[classes] as labour,
resultUC.[probabilities] as labourProbability
INTO
sql
FROM
subquery INNER JOIN subquery2 ON subquery.id = subquery2.id
AND DATEDIFF(second, subquery, subquery2) BETWEEN 0 AND 20
SELECT
*
INTO
c2d
FROM
subquery INNER JOIN subquery2 ON subquery.id = subquery2.id
AND DATEDIFF(second, subquery, subquery2) BETWEEN 0 AND 20
我尝试使用 Inner Join 来连接两个子查询,但它适用于第二个查询,不适用于第一个查询。当我在第一个查询中使用 Inner Join 时,它会显示错误。
列名无效:“id”。具有该名称的列不存在。
有什么解决办法吗?
【问题讨论】:
你为什么不直接从 sql 中选择 * INTO c2d? 【参考方案1】:由于您连接了两个源 subquery
和 subquery2
,因此您需要像在 ON 子句 (subquery.id = subquery2.id
) 中那样使用源名称来限定列。
仅当您有单一来源时才允许使用非限定名称,例如在 subquery
步骤中。
更改列引用以完全限定它们,如下所示:
SELECT
subquery.id as id,
subquery.username as username,
subquery.startTime as startTime,
subquery.endTime as endTime,
...
【讨论】:
以上是关于流分析:Inner Join 两个子查询的主要内容,如果未能解决你的问题,请参考以下文章
流分析:源“子查询”只能用于使用“datediff”函数的时间谓词
INEXISTS的相关子查询用INNER JOIN 代替--性能优化