在 MySQL 中将行转置为列 [英] Transpose rows into columns in MySQL

查看:34
本文介绍了在 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

这篇关于在 MySQL 中将行转置为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆