What Grafana version and what operating system are you using?
grafana 8.3.3 / windows 10 64
What are you trying to achieve?
I’m trying to calculate the total number of records in a table panel with data from mysql
How are you trying to achieve it?
To get the total number of records my query is something like SELECT COUNT(*) FROM table. The total number should be 1534 and the query result indeed is 1534.
In my panel i’m using variables to select certain records. To get the total of selected records i’m using a field holding only values of 1. So to get the number of selected records i’m using a query like SELECT sum(field_with_only_ones) FROM table.
What happened?
What i don’t understand is that WITHOUT making any selection at all the sum of the query is 1529 and not 1534. So i’m missing 5 records.
What did you expect to happen?
SELECT sum(field_with_only_ones) FROM table = SELECT COUNT(*) FROM table
Furthermore i noticed that there’s a difference between sum and SUM. For instance using SUM conditional coloring does not work, using sum it’s working fine.
Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
No.
Did you follow any online instructions? If so, what is the URL?
No.
SELECT SUM(`Anomalie_model`)
FROM `anomalieen`
WHERE `Id` IN (${Id:csv}) AND `Boekingen_nr` IN (${Boekingnr:csv}) AND `Tijdstip` IN ($Tijdstip) AND `Docnr` IN (${Docnr:csv}) AND `Rgl` IN (${Rgl:csv}) AND `Relatienr` IN (${Relatienr:csv}) AND `Grootboek` IN (${Grootboek:csv}) AND `Kostenplaats` IN (${Kostenplaats:csv}) AND `Object` IN (${Object:csv}) AND `Project` IN (${Project:csv}) AND `Bedrag` IN (${Bedrag:csv}) AND `Score` IN (${Score:csv}) AND `Anomalie_status` IN (${Anomalie_status:csv}) AND `Anomalie_andere_audit` IN (${Anomalie_verschillende_audits:csv}) AND `Label_model` IN ($Label_model) AND `Anomalie_auditor` IN (${Anomalie_auditor:csv}) AND `Toelichting_auditor` IN ($Toelichting_auditor)
All values of the template variables: All (so no selection being made)
All field values in field Anomalie_model from table anomalieen: 1 (checked with mysql client / without Grafana)
Result from this query: 1529 records
edit the query in Grafana term by term, removing one instance of “AND Anomalie_status IN (${Anomalie_status:csv})” etc at a time, perform the
query after removing it, and stop when you find the number changes from 1529 to
1534
or
copy the full query you’re using in Grafana into the MySQL client, and
replace every instance of a template variable with “1”, and see whether you
get 1529. If you do, perform the above “remove terms one by one” until the
result changes to 1534.
I’m just thinking that the second option might be simpler and quicker to
achieve the same result.
Incidentally, the problem is not due to the term “AND Anomalie_andere_audit
IN (${Anomalie_verschillende_audits:csv})”, is it?
It’s the only condition where the database field name does not match the
Grafana template variable name…
Did some more research and it looks like records are not selected when three conditions are met:
the field in mysql is DOUBLE
the field in mysql contains values with more than 2 decimals
in mysql the field type is changed from DOUBLE to DECIMAL.
When these three conditions are met Grafana is unable to select the corresponding records. Selecting both with and without template variables, so i don’t think it has anything to do with template variables.
It looks like mysql field type DECIMAL somehow is not (fully) supported in Grafana.