sql查询将所有列合并到一个列中

0qx6xfy6  于 2021-07-29  发布在  Java
关注(0)|答案(1)|浏览(419)
id college1  college2  college3
   1 abc       xyz        rst

以上是输入-
寻找输出:-

id college1  college2  college3
 1  abc 
 1  xyz
 1  rst
m528fe3b

m528fe3b1#

一种方法是 union all :

select id, college1 as college from t
union all
select id, college2 as college from t
union all
select id, college3 as college from t;

这需要扫描table三次,这通常是好的。但是,如果“t”是一个非常复杂的查询或非常大的表,则有更有效的方法。

相关问题