满足 Azure 流分析 SAQL 条件时的默认字段值
Default field value if a condition satisfies in Azure Stream Analytics SAQL
我需要根据文档中可用的另一个字段的值来设置一个字段的值。
下面是我为获取需求而尝试的 SAQL。
WITH INPUT01 AS (
SELECT
input.id AS ID,
ROUND(input.sig,5) AS SIG,
input.dtcTriggeredDateTime.dateTime.time AS TIME,
input.Description as DESC
FROM [inputsignals] as input
WHERE GetArrayLength(input.abc) =0 AND (input.Description = 'xyz' OR input.Description = 'pqr')
SELECT
ID,
SIG,
TIME,
001 AS NUMID
INTO [cosmosDB]
FROM INPUT01
WHERE DESC = 'abc'
SELECT
ID,
SIG,
TIME,
002 AS NUMID
INTO [cosmosDB]
FROM INPUT01
WHERE DESC = 'pqr'
如果 DESC 是 abc 那么 NUMID 应该是 001 如果 DESC 是 pqr 那么 NUMID 应该是 002.
除了单独编写最后两个 select 语句之外,是否有任何选项可以将其写入单个 SELECT 查询中,如下所示?
SELECT
ID,
SIG,
TIME,
001 AS NUMID (If DESC = abc)
002 AS NUMID (If DESC = pqr)
INTO [cosmosDB]
FROM INPUT01
请在 SA SQL:
中使用 CASE...WHEN... 运算符
SELECT
CASE
WHEN DESC = 'abc' THEN 001
WHEN DESC = 'pqr' THEN 002
END as NUMID
FROM INPUT01
我需要根据文档中可用的另一个字段的值来设置一个字段的值。
下面是我为获取需求而尝试的 SAQL。
WITH INPUT01 AS (
SELECT
input.id AS ID,
ROUND(input.sig,5) AS SIG,
input.dtcTriggeredDateTime.dateTime.time AS TIME,
input.Description as DESC
FROM [inputsignals] as input
WHERE GetArrayLength(input.abc) =0 AND (input.Description = 'xyz' OR input.Description = 'pqr')
SELECT
ID,
SIG,
TIME,
001 AS NUMID
INTO [cosmosDB]
FROM INPUT01
WHERE DESC = 'abc'
SELECT
ID,
SIG,
TIME,
002 AS NUMID
INTO [cosmosDB]
FROM INPUT01
WHERE DESC = 'pqr'
如果 DESC 是 abc 那么 NUMID 应该是 001 如果 DESC 是 pqr 那么 NUMID 应该是 002.
除了单独编写最后两个 select 语句之外,是否有任何选项可以将其写入单个 SELECT 查询中,如下所示?
SELECT
ID,
SIG,
TIME,
001 AS NUMID (If DESC = abc)
002 AS NUMID (If DESC = pqr)
INTO [cosmosDB]
FROM INPUT01
请在 SA SQL:
中使用 CASE...WHEN... 运算符SELECT
CASE
WHEN DESC = 'abc' THEN 001
WHEN DESC = 'pqr' THEN 002
END as NUMID
FROM INPUT01