将行转换为MySQL中的列

时间:2022-07-03 04:23:56

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

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

1 个解决方案

#1


10  

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.

您可以使用GROUP_CONCAT将行转换为列,但不能以任何自动方式转置整个结果集。您可以编写一个手动生成每列的查询,也可以在应用程序中执行此操作。

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

这是一个关于编写复杂查询来模拟转置的教程:

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

#1


10  

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.

您可以使用GROUP_CONCAT将行转换为列,但不能以任何自动方式转置整个结果集。您可以编写一个手动生成每列的查询,也可以在应用程序中执行此操作。

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

这是一个关于编写复杂查询来模拟转置的教程:

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