在 MySQL 中将行转置为列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4943496/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transpose rows into columns in MySQL
提问by Even
How can I convert rows into columns in a MySQL query?
如何在 MySQL 查询中将行转换为列?
回答by Dan Grossman
You can turn rows into acolumn 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:
这是一个关于编写复杂查询以模拟换位的教程: