如何使用SQL将矩阵转换为可用的表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用SQL将矩阵转换为可用的表相关的知识,希望对你有一定的参考价值。

我正在努力将矩阵转换为可用的表,但是无法通过使用SQL提出创造性的方法并基本上重构整个文件

任何帮助/建议将不胜感激。

之前

     A       B       C       D
1   .5      .6      .7      .8      
2   .9      1.0     1.1     1.2
3   1.3     1.4     1.5     1.6
4   1.7     1.8     1.9     2.0

X       Y       Result
A       1       .5
A       2       .9
A       3       1.3
A       4       1.7
.....
答案

mysql中,最简单的方法可能是union all

select 'A' as x, col1 as y, A as result from t union all
select 'B' as x, col1 as y, B as result from t union all
select 'C' as x, col1 as y, C as result from t union all
select 'D' as x, col1 as y, D as result from t;

以上是关于如何使用SQL将矩阵转换为可用的表的主要内容,如果未能解决你的问题,请参考以下文章