sql语句之 多列合并为一列

sql 2005

select value
from yourtable
unpivot
(
  value
  for col in (I1, I2, I3)
) un
order by id, col;

sql 2008+

select value
from yourtable
cross apply
(
    values
        ('I1', I1),
        ('I2', I2),
        ('I3', I3)
) c(col, value)
where value is not null
order by id, col

 

posted @ 2018-01-17 15:05  张追逐  阅读(3055)  评论(0编辑  收藏  举报