可能最简单的使用union all
:
select a, b, c, 'D' as which, d as val from t union all
select a, b, c, 'E', e from t union all
select a, b, c, 'F', f from t union all
select a, b, c, 'G', g from t union all
select a, b, c, 'H', j from t union all
select a, b, c, 'I', i from t ;
这是simplest方式,但不是最有效的。它将为每一列扫描一次表。对于不太大的表,从性能角度来看这可能没问题(表缓存在内存中)。
如果“表”确实是一个视图,那么性能可能是一个更重要的问题。