Join examples
Examples that join several streams, and that join a stream with a temporal table.
Join several streams
Join several streams, and add up the clicks for each name:
SELECT o.name, SUM(d.clicks) AS total_clicks
FROM click_stream o
JOIN orgs r ON o.org_id = r.org_id
JOIN models d ON d.org_id = r.org_id
GROUP BY o.name;
The results of this query update as new rows arrive. To aggregate the joined rows in time windows, use an interval join or a temporal join instead. For more information, see Creating interval joins.
Join a stream with a temporal table
Get the rate that is valid when each order arrives:
SELECT o.amount, o.currency, r.rate, o.amount * r.rate AS converted_amount
FROM Orders AS o
JOIN LatestRates FOR SYSTEM_TIME AS OF o.proctime AS r
ON r.currency = o.currency;
In this example, proctime is a processing-time attribute of
Orders, and LatestRates is a lookup table, such as a JDBC
table. For more information, see Creating lookup joins.
