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

Issue

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

Solution

  • $__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);

Answered By – Ashok Kumar Thangaraj

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published