Influxdb queries with grafana

Hi,

this query is returning error in grafana:

SELECT (
( SELECT last(“ProjectRoom_time_unix”) FROM “EMS-Smart-IOT-Device-test” WHERE $timeFilter ORDER BY time DESC LIMIT 1) - ( SELECT last(“ProjectRoom_time_unix”) FROM “EMS-Smart-IOT-Device-test” WHERE $timeFilter ORDER BY time ASC LIMIT 1)
) as “DIFF” WHERE $timeFilter

Error:

Can anyone help me in rectifying this query.
Thanks in advance

Hi, you may find better answers about this at influx community.

Beside that, I would run 2 queries then do the extraction with grafana using new transform feature.
Also, if I understand correctly, you are extracting the highest number from the lowest number. So, you can also use influxql’s spread() function.