I got this error when tried to execute this:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1
Can't seems to find what is the problem. Appreciate if anyone can help
SET @sql = NULL;
SELECT
GROUP_CONCAT(
DISTINCT CONCAT (
"SUM(IF(DATE(FROM_UNIXTIME(machine_stop)) = '",
DATE(FROM_UNIXTIME(machine_stop)),"' ,
(machine_start-machine_stop)/3600, 0)) AS ",
DATE(FROM_UNIXTIME(machine_stop))
)
) INTO @sql
FROM
downtime_data
WHERE
DATE(FROM_UNIXTIME(machine_stop)) >= DATE(NOW()) - INTERVAL 7 DAY;
SET @sql = CONCAT("SELECT
failure_code, ", @sql, "
FROM
downtime_data
WHERE
p.machine='HH1' AND
DATE(FROM_UNIXTIME(machine_stop)) >= DATE(NOW()) - INTERVAL 7 DAY
GROUP BY
failure_code,
DATE(FROM_UNIXTIME(machine_stop))"
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;