[英]Reuse the result from subquery in Azure Stream Analytics Query
I am using Azure Stream Analytics and I am facing some problem on query part. 我正在使用Azure流分析,并且在查询部分遇到了一些问题。 Here is my codes.
这是我的代码。
WITH subquery as (
SELECT
messageId,
deviceId,
temperature,
humidity,
EventProcessedUtcTime,
DemoML(temperature, humidity) as result1
from DemoInput
)
SELECT
messageId as messageId,
deviceId as deviceId,
temperature as temperature,
humidity as humidity,
EventProcessedUtcTime as EventProcessedUtcTime,
result1.[Scored Labels] as result,
result1.[Scored Probabilities] as resultProbability
INTO
[DemoOutput]
FROM
[subquery]
SELECT
result1
INTO
[c2d]
FROM
[subquery]
DemoML is a function where it will return the result. DemoML是一个函数,它将返回结果。 I want to put result1 into two different outputs.
我想将result1放入两个不同的输出中。 But I only managed to put result1 into one output.
但是我只设法将result1放到一个输出中。 How can I achieve that?
我该如何实现? I am totally new to SQL.
我对SQL完全陌生。
You could use INSERT ... OUTPUT ... INTO ... SELECT
to insert twice: 您可以使用
INSERT ... OUTPUT ... INTO ... SELECT
插入两次:
WITH subquery as (
SELECT
messageId,
deviceId,
temperature,
humidity,
EventProcessedUtcTime,
DemoML(temperature, humidity) as result1
from DemoInput
)
INSERT INTO target_1(col1,...)
OUTPUT inserted.col1, ...
INTO target_2(col1, ..)
SELECT
messageId as messageId,
deviceId as deviceId,
temperature as temperature,
humidity as humidity,
EventProcessedUtcTime as EventProcessedUtcTime,
result1.[Scored Labels] as result,
result1.[Scored Probabilities] as resultProbability
FROM [subquery];
Simplified: 简化:
CREATE TABLE t1(i INT);
CREATE TABLE t2(i INT);
CREATE TABLE src(i INT);
INSERT INTO src(i) VALUES(10),(20);
INSERT INTO t1(i) -- target one
OUTPUT inserted.i
INTO t2(i) -- target two
SELECT i
FROM src;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.