Hexory
05/04/2023, 8:50 PMCREATE TABLE Datapoint (
device_id LONG,
sensor_id LONG,
timestamp TIMESTAMP,
value DOUBLE
) timestamp (timestamp) PARTITION BY YEAR;
I want to display this table in a Grafana panel. I want to have one series per sensor, but cant find the proper query syntax. Anyone can give me a hand? 🙂
I have this for now
SELECT
timestamp as time,
sensor_id,
avg(value) as value
FROM Datapoint
WHERE $__timeFilter(timestamp) AND device_id=0
SAMPLE BY $__interval;
This give me a line for sensor_id and value. I want a line per sensor_id with their value.
I tried with group and partition clause, but without sucess.
Any idea?
Thanks!Gabriel Mocan
05/04/2023, 9:08 PMdevice_id
so you can query all devices in one query and plot them on chart.
SELECT DISTINCT device_id FROM Datapoint
Tick both “Multi-value” and “Include All option” then click on update; set the variable to All.
SELECT
$__time(timestamp),
sensor_id as metric,
avg(value) as value
FROM Datapoint
WHERE $__timeFilter(timestamp) AND device_id in ($device_id)
SAMPLE BY $__interval;
Hexory
05/04/2023, 9:16 PMpq: cannot compare TIMESTAMP with type CHAR
Gabriel Mocan
05/04/2023, 9:20 PMHexory
05/04/2023, 9:24 PMGabriel Mocan
05/04/2023, 9:24 PMHexory
05/04/2023, 9:25 PMGabriel Mocan
05/04/2023, 9:25 PMHexory
05/04/2023, 9:25 PMSELECT
$__time(timestamp),
sensor_id as metric,
avg(value) as value
FROM Datapoint
WHERE $_timeFilter(timestamp) AND device_id = 0
SAMPLE BY $__interval;
Gabriel Mocan
05/04/2023, 9:26 PMselect * from Datapoint
?Hexory
05/04/2023, 9:27 PMGabriel Mocan
05/04/2023, 9:29 PMHexory
05/04/2023, 9:30 PMGabriel Mocan
05/04/2023, 9:31 PMHexory
05/04/2023, 9:31 PMGabriel Mocan
05/04/2023, 9:31 PMHexory
05/04/2023, 9:32 PMGabriel Mocan
05/04/2023, 9:33 PMHexory
05/04/2023, 9:36 PMGabriel Mocan
05/04/2023, 9:37 PMHexory
05/04/2023, 9:57 PMSELECT
$__time(timestamp),
avg(value) AS value,
device_id || sensor_id AS metric
FROM Datapoint
WHERE $__timeFilter(timestamp) AND cast(device_id as String) in ($device_id)
SAMPLE BY $__interval FILL(0)
Gabriel Mocan
05/04/2023, 10:02 PM