Chaining Queries in Stream Analytics

c.mavi01 0 Reputation points
2023-11-25T05:33:16.8333333+00:00

How can I write multiple SQL queries where the output of one query serves as the input to the next query, and this process repeats for several levels? I am working with around 3 or more levels of queries.

Azure Stream Analytics
Azure Stream Analytics
An Azure real-time analytics service designed for mission-critical workloads.
333 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sander van de Velde 29,281 Reputation points MVP
    2023-11-25T13:10:29.3266667+00:00

    Hello @c.mavi01 ,

    welcome to this moderated Azure community forum.

    If you want to write queries to be reuse, check the WITH clause.

    Example from that site:

    WITH   
    NormalReadings AS  
    (  
      SELECT *  
      FROM Sensor  
      WHERE Reading < 100 AND Reading > 0  
    ),  
    Averages AS  
    (  
      SELECT SensorId, AVG(Reading) as AvgNormalReading  
      FROM NormalReadings  
      GROUP BY SensorId, TumblingWindow(minute, 1)  
    ),  
    BadAverages AS  
    (  
      SELECT *  
      FROM Averages  
      WHERE AvgNormalReadings < 10  
    )  
      
    SELECT * INTO outputAlerts FROM BadAverages  
    SELECT * INTO outputLog FROM NormalReadings  
    

    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments