I have a query, I want to write it in php but its showing error.
My query is like below:
$exe1 = mysql_query("
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'SUM(CASE WHEN `size_name` = ''',
`size_name`,
''' THEN Quantity ELSE 0 END) AS `',
`size_name`, '`'
)
) INTO @sql
FROM Size;
SET @sql = CONCAT('SELECT st.Style , ', @sql, '
FROM Size s
JOIN Style st ON s.style_id = st.id
GROUP BY st.Style
');
PREPARE stmt FROM @sql;
EXECUTE stmt;") or die(mysql_error());
But its showing the message
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 'SET @sql = CONCAT('SELECT st.Style , ', @sql, ' FROM Size s ' at line 12
I just dont know how to solve this error. Can anyone please help me to solve this problem?