Supported clauses
The SELECT
statement is used to retrieve data from one or more views.
Amazon IoT SiteWise supports the JOIN
and INNER JOIN
operations.
Views are joined with an explicit JOIN
syntax, or with comma-separated notations in the FROM
clause.
A general SELECT
statement:
SELECT expression [, ...] [ FROM table_name AS alias [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition ] [ ORDER BY expression [ ASC | DESC ] [ NULLS FIRST | NULLS LAST ] [, ...] ] [ LIMIT expression ]
A SELECT statement with the different clauses:
SELECT a.asset_name, a.asset_id, p.property_type, p.property_data_type, p.string_attribute_value, p.property_name FROM asset a, asset_property p WHERE a.asset_description LIKE '%description%' AND p.property_type IN ('attribute', 'metric') OR p.property_id IN ( SELECT property_id FROM raw_time_series WHERE event_timestamp BETWEEN TIMESTAMP '2025-01-01 00:00:00' AND TIMESTAMP '2025-01-02 00:00:00' GROUP BY asset_id, property_id HAVING COUNT(*) > 100 ) GROUP BY p.property_type HAVING COUNT(*) > 5 ORDER BY a.asset_name ASC LIMIT 20;
Note
An implicit JOIN
combines two or more different tables without using the JOIN
keyword
based on Amazon IoT SiteWise's internal schema. This is the equivalent of performing a JOIN
on the
asset_id
and property_id
fields between metadata and raw data tables.
This pattern allows SiteWise to leverage any given metadata filters in the query,
when fetching from raw data tables in a way that results in less overall data scanned.
Example of a query:
SELECT a.asset_name, p.property_name, r.event_timestamp FROM asset a, asset_property p, raw_time_series r WHERE a.asset_name='my_asset' AND p.property_name='my_property'
The above example only scans data from the asset property belonging to the specified metadata names.
Example of a less optimized equivalent of the above query:
SELECT a.asset_name, p.property_name, r.event_timestamp FROM asset a JOIN asset_property p ON a.asset_id=p.asset_id JOIN raw_time_series r ON p.asset_id=r.asset_id AND p.property_id=r.property_id WHERE a.asset_name='my_asset' AND p.property_name='my_property'
An explanation of each clause and it's description is listed below:
Clause |
Signature |
Description |
---|---|---|
|
|
This clause limits the result set to the specified number of rows. You can use
|
|
|
The |
|
|
The |
|
|
The |
|
|
A |
|
|
|
|
|
An |
|
|
The |