日期:2014-05-18 浏览次数:20533 次
;with f as ( select id=row_number()over(partition by a order by getdate()),* from tb ) select isnull(a.a,'') as a,isnull(b.b,'') as b from (select px=row_number()over(order by getdate()),* from (select distinct id,a from f where id=1)t)a left join (select px=row_number()over(order by getdate()),* from (select distinct id,b from f where id=1)t)b on a.px=b.px
;with f as ( select id=row_number()over(partition by a order by getdate()),* from tb --按照A列排序 ) select isnull(a.a,'') as a,isnull(b.b,'') as b --A列,B列有值的直接列出,没有的就显示为空字符 from (select px=row_number()over(order by getdate()),* from (select distinct id,a from f where id=1)t)a --取出按照A列中的序列(不重复的) left join --俩个序列进行连接 (select px=row_number()over(order by getdate()),* from (select distinct id,b from f where id=1)t)b --取出按照B列中的序列(不重复的) on a.px=b.px