From 9e16cd8af4cf9d6d9bd21530fac899518619f1ec Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Fri, 15 Mar 2024 17:26:36 +0100 Subject: [PATCH] Feature / SQL: Reasonably finish page by ... - providing a canonical powerful SQL example - guiding the reader to the "Advanced Querying" and "All Features" pages --- docs/feature/sql/index.md | 40 +++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/docs/feature/sql/index.md b/docs/feature/sql/index.md index 9d214f74..c2261217 100644 --- a/docs/feature/sql/index.md +++ b/docs/feature/sql/index.md @@ -4,6 +4,8 @@ :::{include} /_include/links.md ::: +:::{include} /_include/styles.html +::: :::::{grid} :padding: 0 @@ -72,10 +74,36 @@ off-the-shelve, 3rd-party, open-source, and proprietary applications. ## Synopsis -:::{todo} -- One or max. two DQL SQL queries using many features, all at once? -- What else? -::: +Use scalar functions, sub-selects, and windowing, specifically illustrating the +DATE_BIN function for resampling time series data using DATE_BIN, also known as +grouping rows into time buckets, aka. time bucketing. + +```sql +SELECT + ts_bin, + battery_level, + battery_status, + battery_temperature +FROM ( + SELECT + DATE_BIN('5 minutes'::INTERVAL, "time", 0) AS ts_bin, + battery_level, + battery_status, + battery_temperature, + ROW_NUMBER() OVER (PARTITION + BY DATE_BIN('5 minutes'::INTERVAL, "time", 0) + ORDER BY "time" DESC) AS "row_number" + FROM doc.sensor_readings +) x +WHERE "row_number" = 1 +ORDER BY 1 ASC +``` + + +## Learn + +Please inspect more advanced SQL capabilities on the [](#query) page, +and read about [](#features) in general. @@ -87,7 +115,3 @@ off-the-shelve, 3rd-party, open-source, and proprietary applications. [](#timeseries) • [](#machine-learning) ::: - - -```{include} /_include/styles.html -```