我正在使用Azure Stream Analytics,我在查询部分遇到了一些问题。这是我的代码。
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是一个返回结果的函数。我想将result1放入两个不同的输出中。但我只设法将result1放入一个输出。我怎样才能做到这一点?我对SQL完全不熟悉。
答案 0 :(得分:0)
您可以使用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];
简化为:
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;
<强> DBFiddle Demo 强>