DuckDB 2 cheatsheet
DuckDB 2: SQL features
9 common DuckDB 2 tasks.
Create a table from a file
Load a CSV into a table in one statement.
CREATE TABLE sales AS SELECT * FROM read_csv('sales.csv');
Summarize every column
Get min, max, quartiles, unique counts and null percentages for each column.
SUMMARIZE sales;
Group by all non-aggregated columns
Skip listing the grouping columns by hand.
SELECT region, product, sum(amount) AS total FROM sales GROUP BY ALL;
Filter on a window function
QUALIFY filters rows after window functions are calculated, without a subquery.
SELECT * FROM sales QUALIFY row_number() OVER (PARTITION BY region ORDER BY amount DESC) = 1;
Select all columns except some
Leave out columns without listing the rest.
SELECT * EXCLUDE (internal_id) FROM sales;
Pivot rows into columns
Turn category values into columns.
PIVOT sales ON region USING sum(amount) GROUP BY product;