提问者:小点点

用于将所有列合并为单个列的Sql查询


  id college1  college2  college3
   1 abc       xyz        rst

上面是输入-

正在查找输出:-

id college1  college2  college3
 1  abc 
 1  xyz
 1  rst

共1个答案

匿名用户

一种方法简单地称为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;

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