Skip to content

CORE FIELD

Run a safe query in SQL Lab

Full PDF

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
Sensor history
TiempoTime
timestamp · by hour
MétricaMetric
AVG(CPPW)
RangoRange
8 hours ending at the latest reading

Before you run it

  • Confirm that you selected the connection and sensor area authorized for your role.
  • Start with SELECT; do not use UPDATE, DELETE, or DROP.
  • Limit the period and request only the columns you need.

In this public SQL, <fuente_autorizada_de_sensores> is a placeholder. Replace it inside CORE FIELD with the source authorized for your account; do not publish that identifier.

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 `<fuente_autorizada_de_sensores>`
WHERE `timestamp` >= (
SELECT DATE_SUB(MAX(`timestamp`), INTERVAL 8 HOUR)
FROM `<fuente_autorizada_de_sensores>`
)
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.

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.