No success to bring SQL Query transfered in Grafana

Dear Community,

I have a mysql Table with logs from my POE Switch and the Data will updated every minute.
To display each Port is no problem.
My Problem is to display the AVG from all Ports and this for each 5 Minutes.
When I try this in MySql it works with the attached Query.
I trie a lot to insert this in Grafana but I am not successful.
It starts that Grafana cannot use LIKE and I found also no solution for this.
Maybe somebody can compleate the Query or give me a hand to find a solution.

SELECT round(AVG(VALUE),2) AS 'AVG per 5 min', FROM_UNIXTIME((UNIX_TIMESTAMP(TIMESTAMP) div (5*60))*(5*60)+(5*60)) as timeIntervals 
FROM history 
WHERE device = "Switch_24_PoE_250W"
AND Reading LIKE 'port_%_poe_voltage' 
AND VALUE <> 0
GROUP BY timeIntervals ASC;

Thanks

Thomas

hmmmm…I can’t hep but wonder if a monitoring solution like Prometheus is better suited for this kind of work. It has built-in functions like avg_over_time that are designed to return these sorts of rolling aggregations: