我正在尝试在 phpMyAdmin 中执行此代码。但是,我收到以下错误
#1054 - “字段列表”中的未知列“年份”
SELECT
CONCAT('SELECT year2,',
GROUP_CONCAT(sums),
' FROM yourtable GROUP BY year2')
FROM (
SELECT CONCAT('SUM(name=\'', name, '\') AS `', name, '`') sums
FROM yourtable
GROUP BY name
ORDER BY COUNT(*) DESC
) s
INTO @sql;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
查看fiddle的实现。
如何解决这个问题?以及如何在 PHP 中编写脚本的任何想法?