面试题:查询所有上级SQL

image

[customer] 写错了,该写bossone

求 User10 User20 User30 User60 的所有上级

image

select a.id,a.[User] ,a.customer as bossone,bosstwo = b.[customer]

,bossthree = c.customer from tem a

left join tem b on a.customer = b.[user]

left join tem c on b.customer = c.[user]

where a.[User] = 'user10' or a.[User] = 'user20' or a.[User] = 'user30' or a.[User] = 'user60'
原文地址:https://www.cnblogs.com/tangge/p/2233617.html