在Azure Stream Analytics Query中,如何获取组的第一个值?

时间:2016-07-18 18:04:05

标签: azure-stream-analytics

我的输入如下fqn,v,t。我需要获得组中的第一个v值。以下是我的查询。我需要组中的第一个v值

SELECT
v
fqn, min(t) as timeslot
INTO
[finalalloutput]
FROM
[finalallinput] timestamp by t
where fqn not like '%Production%' 
group by TumblingWindow(minute, 1),fqn

1 个答案:

答案 0 :(得分:3)

这是编写查询的最短方式:

SELECT 
    t, v, fqn
FROM
    [finalallinput] timestamp by t
WHERE 
    IsFirst(minute, 1) OVER (WHEN [fqn] not like '%Production%') = 1

但您也可以使用TopOne聚合函数执行相同的操作:

WITH step1 AS
(
SELECT
    TopOne() OVER (ORDER BY t ASC) firstEvent,
    fqn, min(t) as timeslot
FROM
    [finalallinput] timestamp by t
WHERE 
    fqn not like '%Production%' 
GROUP BY
    TumblingWindow(minute, 1),fqn
)

SELECT 
    firstEvent.v,
    fqn,
    timeSlot
INTO
[finalalloutput]
FROM step1