Introduction
Imagine you want to understand how a machine behaved yesterday or last week to find out why it stopped working. Querying historical data helps you look back at past information collected by a system to find patterns or problems.
Jump into concepts and practice - no test required
Think of a security camera that records everything happening in a store. Later, if something goes wrong, you can watch the recordings to see what happened and when. Querying historical data is like searching through those recordings to find specific moments.
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ Data │ │ Data │ │ Querying │ │ Data │ │ Collection │────▶│ Storage │────▶│ Methods │────▶│ Analysis │ │ (Sensors) │ │ (Historian) │ │ (User Queries)│ │ (Insights) │ └───────────────┘ └───────────────┘ └───────────────┘ └───────────────┘
SELECT timestamp, value FROM readings WHERE sensor_id = 'S2' AND timestamp BETWEEN '2024-03-01' AND '2024-03-05' ORDER BY timestamp DESC LIMIT 3;SELECT * FROM readings WHERE sensor_id = 'P1' AND timestamp > '2024-02-01' AND type = 'pressure'