Mysql: pivot table working in sqlfiddle but not working in phpmyadmin

大城市里の小女人 提交于 2019-12-25 07:07:06

问题


i have a pivot table code that worked in the sqlfiddle, I can't seem to get the query working when I bring it back onto my database in phpmyadmin.

Here is my sqlfiddle.

when I run it in my localHost phpmyadmin, the query becomes something like below:

SET @@group_concat_max_len = 5000;# MySQL returned an empty result set (i.e. zero rows).
SET @sql = NULL;# MySQL returned an empty result set (i.e. zero rows).
SELECT GROUP_CONCAT(DISTINCT
        CONCAT('MAX(IF(hw_id = ', hw_id, ', score, -1)) AS ',
               CONCAT('`hw', hw_id, '`'))) INTO @sql
                      FROM mk;# 1 row affected.
SET @sql = CONCAT('SELECT st.id, ', @sql,
     ' FROM st LEFT JOIN mk ON st.id = mk.st_id GROUP BY st.id');
           # MySQL returned an empty result set (i.e. zero rows).
PREPARE stmt FROM @sql;# MySQL returned an empty result set (i.e. zero rows).
EXECUTE stmt;# Rows: 3
DEALLOCATE PREPARE stmt;# MySQL returned an empty result set (i.e. zero rows).

as you can see, I change the group_concat_max_len too... but nothing changed...


回答1:


Build it into a stored procedure, then execute that in phpmyadmin.

If you want to pursue the failing phpadmin, add SELECT @sql; and see if you get the desired query.




回答2:


While analyzing the phpMyAdmin bug reported for this question, I've realized that this query works on some servers and fails on others, so it's rather MySQL server incompatibility than an issue in phpMyAdmin. Different MySQL server versions behave differently in this case (which strictly speaking doesn't follow grammar defined by MySQL documentation).

I've tested:

  • in MySQL 5.5.46 the query fails in both phpMyAdmin and commandline
  • in MariaDB 10.0.24 the query works fine in both phpMyAdmin and commandline


来源:https://stackoverflow.com/questions/35667444/mysql-pivot-table-working-in-sqlfiddle-but-not-working-in-phpmyadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!