Hi there,
I wrote a short mySQL query.
It just counts the amount of entries on a specific day.
SELECT
count(Status) as Anzahl,
DATE_FORMAT(timestamp,"%d-%m-%Y") as Datum
FROM
abteilung.maschine_1
WHERE
DATE_FORMAT(timestamp,"%Y-%m-%d") = DATE('2022-10-27')
Now I would like to count all entries during a dynamic time range I set in the dashboard .
How could I link the set timerange from the dashboard in my query code.
Hi @denniscording ,
Welcome to the community support forums !!
I think you can simply use the time series panel visualisation to do this.
Also (optional), at the v.end of your MySQL query, you can and ORDER by 1,2 so that it will be ordered by anzahl and datum which might be more better.
I hope this helps.
You can use those selected time ranges in a
WHERE
clause. Check these global variables out
Global variables Grafana has global built-in variables that can be used in expressions in the query editor. This topic lists them in alphabetical order and defines them. These variables are useful in queries, dashboard links, panel links, and data...
Thank you for help.
I treyed it with $timeFilter
and $__timeFilter
but both bring me an error.
SELECT
count(Status) as Anzahl,
UNIX_TIMESTAMP(timeStamp) AS "time"
FROM
abteilung.maschine_1
WHERE
$__timeFilter
Error 1054: Unknown column '$__timeFilter' in 'where clause'
I tried that too:
SELECT
count(Status) as Anzahl,
UNIX_TIMESTAMP(timeStamp) AS "time"
FROM
abteilung.maschine_1
WHERE
time = $__timeFilter
Error 1054: Unknown column 'time' in 'where clause'
What am I doing wrong ? It seems to me that $__timeFilter still needs an input, but I would like the filter to use the time range of the dashboard !?