在MySQL中将行转置为列

问题描述:

如何在MySQL查询中将行转换为列?

How can I convert rows into columns in a MySQL query?

您可以使用GROUP_CONCAT将行变成 a 列,但不能以任何自动方式转置整个结果集.您可以编写一个查询来手动生成每一列,也可以在应用程序中完成.

You can turn rows into a column with GROUP_CONCAT, but you can't transpose whole result sets in any automatic way. You either write a query that produces each column manually, or you do it in an application.

这是有关编写复杂查询以模拟换位的教程:

Here's a tutorial on writing the complicated queries to emulate the transposition:

http://www.artfulsoftware.com/infotree/queries.php#78