Home > front end >  How to reflect the built-in time-browser filter into a mysql query in Grafana?
How to reflect the built-in time-browser filter into a mysql query in Grafana?

Time:08-31

This is my query which needs to get modified for reflecting the time filters:

SELECT DATE AS TIME,mbps
FROM overage
WHERE DATE >= (CASE WHEN (DAY(CURDATE()) = 1 OR DAY(CURDATE()) = 2 OR DAY(CURDATE()) = 3 OR DAY(CURDATE()) = 4) THEN CONCAT(YEAR(CURDATE()),'-', MONTH(CURDATE() - INTERVAL 1 MONTH),'-04') ELSE CONCAT(YEAR(CURDATE()),'-', MONTH(CURDATE()),'-04') END) AND DATE <= (CURDATE() - INTERVAL 1 DAY)
ORDER BY DATE

CodePudding user response:

  • $__timeFilter(column) -> column BETWEEN FROM_UNIXTIME(1492750877) AND FROM_UNIXTIME(1492750877)

Use this:

SELECT 
    date as time,
    mbps 
FROM overage 
WHERE $__timeFilter(date) 
GROUP BY DATE(date);
  • Related