Skip to content

Run a safe query in SQL Lab

SQL Lab helps answer questions that require preparing data before you build a chart.

Pregunta real de plantaReal plant question

What was the average CPPW value in each of the last eight recorded hours?

FuenteSource
robotic.sensor_data
TiempoTime
timestamp · by hour
MétricaMetric
AVG(CPPW)
RangoRange
8 hours ending at the latest reading

Before you run it

  • Confirm that the database is Aurora MySQL (Data API).
  • Confirm the robotic schema.
  • Start with SELECT; do not use UPDATE, DELETE, or DROP.
  • Limit the period and request only the columns you need.
SELECT
FROM_UNIXTIME(
FLOOR(UNIX_TIMESTAMP(`timestamp`) / 3600) * 3600
) AS hora,
AVG(`CPPW`) AS promedio_cppw,
MIN(`CPPW`) AS minimo_cppw,
MAX(`CPPW`) AS maximo_cppw,
COUNT(*) AS lecturas
FROM `robotic`.`sensor_data`
WHERE `timestamp` >= (
SELECT DATE_SUB(MAX(`timestamp`), INTERVAL 8 HOUR)
FROM `robotic`.`sensor_data`
)
AND `CPPW` IS NOT NULL
GROUP BY hora
ORDER BY hora;

Run and read the result

  1. Select Run.
  2. Wait for the rows and execution time to appear.
  3. Confirm that hora is sorted.
  4. Check that minimum ≤ average ≤ maximum.
  5. Use lecturas to spot hours with too few readings.
SQL Lab with the editor, schema, and query results visible
The structure is the same for CPPW or THHN_1: context on the left, query above, and evidence below.

Save, download, or convert

  • Save query: keeps the SQL so you can run or review it later.
  • Query history: helps recover a previous run and see whether it failed.
  • Download CSV: exports the visible rows for work outside CORE FIELD.
  • Save as dataset: turns the query into a virtual source for Explore.
Resultado esperadoExpected result

The query returns one row per hour, with coherent values and without changing the original records.

To reuse the result in several charts, continue with Create and maintain a virtual dataset.