select p1,p3 as p2 from ( select *,ROW_NUMBER() over(partition by p2 order by p1) rk from (select t1.p1 p1,t1.p2 p2,t2.p1 p3,t2.p2 p4 from friend t1 left join friend t2 on t1.p2=t2.p2 and t1.p1!=t2.p1 union select t3.p2,t3.p1,t4.p2,t4.p1 from friend t3 left join friend t4 on t3.p1=t4.p1 and t3.p2!=t4.p2 ) t5 where p3 is not null )t6 where rk=1 ——原创代码 我写的是最简单的解法吗?
点赞 评论

相关推荐

牛客网
牛客企业服务