-
What Grafana version and what operating system are you using?
Grafana 11.3, Mac OS -
What are you trying to achieve?
Run dynamic sql script to query data from table in MySQL data source, the script likes:
SET @sql = CONCAT('SELECT business_unit, product_name, target, ‘,
(SELECT GROUP_CONCAT(DISTINCT CONCAT(‘MAX(CASE WHEN month = '’, month, ‘' THEN value END) AS', month, '
’))
FROM (select business_unit, product_name, target, value, month from t_monthly_supp_avai_report where
STR_TO_DATE(month, ‘%Y/%m’) <= STR_TO_DATE(CONCAT(‘2024’, ‘/’, ‘12’), ‘%Y/%m’) order by month desc ) subquery ),
’ FROM t_monthly_supp_avai_report
GROUP BY product_name’
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
-
How are you trying to achieve it?
Create a new dashboard, add visualization, select MySQL datasoruce, switch to code editor, then paste the script in above -
What happened?
Error occurred -
What did you expect to happen?
The script can be execute as well as it runs in MySQL -
Can you copy/paste the configuration(s) that you are having problems with?
Nothing -
Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
[ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use]
- Did you follow any online instructions? If so, what is the URL?
No