流分析:源“子查询”只能用于使用“datediff”函数的时间谓词
Posted
技术标签:
【中文标题】流分析:源“子查询”只能用于使用“datediff”函数的时间谓词【英文标题】:Stream Analytics: Source 'subquery' can only be used in temporal predicate using 'datediff' function 【发布时间】:2018-01-25 12:29:10 【问题描述】:我正在使用 WITH 使用两个子查询查询流分析中的数据。我想组合来自两个子查询的数据并将它们放入 SQL 中。所以,我正在使用 JOIN 函数。
WITH subquery as (
SELECT
id as id,
deviceId as deviceId,
username as username,
try_cast(localtime as datetime) as localtime,
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,
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,
deviceId as deviceId,
username as username,
try_cast(localtime as datetime) as localtime,
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,
deviceId as deviceId,
username as username,
localtime as localtime,
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
在最后一行抛出错误:
源 'subquery' 只能用于使用 'datediff' 函数的时间谓词。
例子:
选择输入1.a,输入2.b 从输入1 在 DATEDIFF(分钟,输入 1,输入 2)在 0 和 10 之间加入输入 2。
请确保时间谓词中没有“或”。
我已按照给出的示例进行操作,但仍然有错误。如何组合这两个子查询?
【问题讨论】:
【参考方案1】:语法错误可能是由您在最后两行中的拼写错误引起的。尝试将“子查询”替换为“子查询”,如下所示:
FROM
subquery
INNER JOIN
subquery2 ON subquery.id = subquery2.id
AND DATEDIFF(second, subquery, subquery2) BETWEEN 0 AND 20
【讨论】:
这么粗心的错误以上是关于流分析:源“子查询”只能用于使用“datediff”函数的时间谓词的主要内容,如果未能解决你的问题,请参考以下文章