没看懂语句,求解释~在线等
泡论坛,看了一条小F姐姐的问题解答,如下:
表T的数据如下,
A B
-------
A1 B1
A1 B2
A2 B1
A3 B2
希望得到
A B
--------
A1 B1
A2 B2
A3
;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 bfrom(select px=row_number()over(order by getdate()),* from (select distinct id,a from f where id=1)t)aleft join (select px=row_number()over(order by getdate()),* from (select distinct id,b from f where id=1)t)bon 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