且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 MySQL 中将行转置为列

更新时间:2023-11-18 22:48:16

你可以用 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