Multiple lines in SQL Query

I have this query: SELECT time, temp, sensor_id FROM temp_data;
I need to sort my temp and time by sensor_id (like I have 3 sensors with ids 1,2,3) and create multiple lines in Time Series Panel.

I tried another questions in grafana but, its too hard to understand it.

I use grafana in docker container!

what version of grafana and what is your datasource? mysql? influxdb?

SELECT time, temp as value, sensor_id as metric 
FROM temp_data

then make sure you choose Time Series as Format in grafana ui

Hello I use mysql database, here is example of data:
id |temp |time |sensor_id|
—±----±------------------±--------+
1|28.13|2024-08-29 17:49:56| 1|
2|28.06|2024-08-29 17:49:56| 2|
3|28.25|2024-08-29 17:49:57| 3|
4|28.13|2024-08-29 17:49:58| 1|
5|28.06|2024-08-29 17:49:58| 2|
6|28.31|2024-08-29 17:49:59| 3|
7|28.19|2024-08-29 17:50:00| 1|
8|28.06|2024-08-29 17:50:00| 2|
9|28.31|2024-08-29 17:50:01| 3|

1 Like

sensor_id integer

you need to make it varchar

CONCAT("", sensor_id)

or some other means, otherwise time series wont like it.

1 Like