Creating and querying a view
Now that you have learned the basic steps of creating a table and querying data from a table, learn how to create a more complex query using views.
In the following example, you create a view using the columns from the created Faker table. In this derived computation that can be saved as a view, the orders are aggregate in half minute intervals based on their status.
Use the following CREATE VIEW
statement, and paste it to the SQL
window.
DROP VIEW IF EXISTS summaries; CREATE VIEW summaries AS SELECT window_start, window_end, order_status, COUNT(*) as order_count, SUM(amount) as total_amount FROM TABLE( TUMBLE(TABLE orders, DESCRIPTOR(order_time), INTERVAL '20' SECONDS)) GROUP BY window_start, window_end, order_status;
To create the view, you need to click on the Execute button under the SQL window.
Before selecting data from this view, you can change the Sample Behavior to sample all messages on the Settings tabs. This way the sampled output is not limited to a given amount of messages.
SELECT * FROM summaries
To execute the query, you need to click on the Execute button under the SQL window.
After a short amount of time, the samples of the aggregated result continously show up under the Results tab.
