I’m setting a variable in Grafana to the following Query from a MySQL Datasource:
SELECT fkid,SUM(value) FROM table WHERE fkid IN ($All_IDs) AND fkbinary > 0 GROUP BY fkid
$All_IDs is an array of IDs produced by this query:
SELECT DISTINCT fkid FROM table WHERE fkid <> 0
When I run the full query including the sub-query in PHPMyAdmin, I get a list of IDs with their corresponding summed values.
When I input the first query to be a second variable called $SummedValues on a Dashboard in Grafana, it only returns the first ID & summed value.
For example, here is output from the full query including sub-query in PHPMyAdmin:
id SUM(value)
1 124
2 33
5 3
24 44
Here is the Preview of Values in Grafana for the Variable of the full query:
1 124
Here is the Preview of Values in Grafana for the sub-query that’s its own Variable:
1
2
5
24
So I’m not sure why it isn’t showing full values or if there’s an option I need to check or something.
If I just put the sub-query into the final variable like so:
SELECT fkid,SUM(value) FROM table WHERE fkid IN (SELECT DISTINCT fkid FROM table WHERE fkid <> 0) AND fkbinary > 0 GROUP BY fkid
That works fine. Odd. It seems like it is failing as it passes through the 2nd variable. ![]()