Is the new Raspberry Pi AI Kit better than Google Coral?
135561 Views
Build Your Own AI Assistant Part 1 - Creating the Assistant
121827 Views
Control Arduino with Python using Firmata / PyFirmata
88872 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
65602 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
60799 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
53953 Views
How to Keep your Raspberry Pi happy
How to Install Pi-Apps on a Raspberry Pi
Pikon II, The Ultimate DIY Raspberry Pi Camera!
Pico Plotter
LEGO Gets Lights & Sound with Tiny FX
Thinkman
DuckDB - Fast, free analytics
1h 36m
Obsidian
1h 0m
Getting Started with C on the Raspberry Pi Pico
0h 50m
Running K3s on Raspberry Pi
1h 28m
From Docker to Podman
1h 2m
MicroPython Robotics Projects with the Raspberry Pi Pico
0h 54m
Learn how to Program in Python, C, Rust, and more.
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
42% Percent Complete
By Kevin McAleer, 4 Minutes
Level up your workflow with CTEs, views, persistence, COPY, and extensions.
Unfamiliar terms like CTE, view, persistence, or PRAGMA? See the Beginner glossary.
CTE stands for Common Table Expression. Think of a CTE as a short‑lived, named subquery you define at the top of your SQL with the WITH keyword. It helps you break a complex query into readable steps.
WITH
Why it matters:
Step by step:
WITH name AS ( …select… )
Example 1 — Single CTE to add a metric and summarize:
WITH enriched AS ( SELECT *, ROUND(tip / NULLIF(total_bill,0) * 100, 2) AS tip_pct FROM tips ) SELECT day, ROUND(AVG(tip_pct), 2) AS avg_tip_pct FROM enriched GROUP BY day ORDER BY avg_tip_pct DESC;
Notes:
NULLIF(total_bill,0)
enriched
You try it (5 min) Add a party_size_band CTE that buckets sizes (1–2 small, 3–4 medium, 5+ large) Join it in the final SELECT and summarize by day, party_size_band
You try it (5 min)
party_size_band
day, party_size_band
Example 2 — Multiple CTE pipeline (clean → enrich → summarize):
WITH cleaned AS ( SELECT * FROM tips WHERE total_bill > 0 ), enriched AS ( SELECT *, ROUND(tip / total_bill * 100, 2) AS tip_pct FROM cleaned ), summarized AS ( SELECT day, time, ROUND(SUM(total_bill), 2) AS revenue, ROUND(AVG(tip_pct), 2) AS avg_tip_pct, COUNT(*) AS orders FROM enriched GROUP BY day, time ) SELECT * FROM summarized ORDER BY revenue DESC;
When to use CTEs vs Views vs Tables:
CREATE OR REPLACE VIEW v_tip_stats AS SELECT day, time, ROUND(SUM(total_bill), 2) AS revenue, COUNT(*) AS orders FROM tips GROUP BY day, time; SELECT * FROM v_tip_stats ORDER BY revenue DESC;
Views store queries, not data. They always reflect the latest underlying data.
-- In the CLI .open analytics.duckdb -- Save results as a physical table CREATE TABLE IF NOT EXISTS tips AS SELECT * FROM read_csv_auto('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv');
Now your data is stored in analytics.duckdb for fast, repeatable queries.
analytics.duckdb
Note: ensure the exports/ folder exists (or change the path) before running COPY.
exports/
-- Export a query to CSV or Parquet COPY ( SELECT day, time, SUM(total_bill) AS revenue FROM tips GROUP BY day, time ) TO 'exports/tip_revenue.parquet' (FORMAT 'parquet');
-- Import local CSV/Parquet CREATE TABLE sales AS SELECT * FROM read_parquet('data/sales/*.parquet');
You try it (3–5 min) Export v_tip_stats to exports/tip_stats.parquet Re-import it as tip_stats_imported and compare COUNT(*)
You try it (3–5 min)
v_tip_stats
exports/tip_stats.parquet
tip_stats_imported
COUNT(*)
Some features ship as extensions. Popular ones:
INSTALL httpfs; -- http, https, s3 LOAD httpfs; INSTALL json; LOAD json;
With httpfs you can query remote files over HTTP/S3. With json you can query JSON via read_json().
httpfs
json
read_json()
PRAGMA version; PRAGMA threads; -- show default threads SET threads = 4; -- adjust parallelism PRAGMA memory_limit='2GB';
.duckdb
< Previous Next >
You can use the arrows ← → on your keyboard to navigate between lessons.
← →