select top 1关联查父级名称

Posted shy1766it

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了select top 1关联查父级名称相关的知识,希望对你有一定的参考价值。

SELECT users.UserID AS Id,
       users.UserName,
       users.TrueName,
       users.Phone,
       users.Email,
       STUFF(
       (
           SELECT , + roles.Description
           FROM Accounts_UserRoles userroles
               LEFT JOIN Accounts_Roles roles
                   ON roles.RoleID = userroles.RoleID
           WHERE userroles.UserID = users.UserID
           FOR XML PATH(‘‘)
       ),
       1,
       1,
       ‘‘
            ) AS RoleNames,
       (
           SELECT TOP 1
                  UserName
           FROM Accounts_Users sup
           WHERE sup.UserID = users.SuperiorId
                 AND users.SuperiorId IS NOT NULL
       ) AS SuperiorName,
       users.Activity,
       users.IsSuperior,
       users.DataRange,
       dept.DeptName
FROM Accounts_Users users
    LEFT JOIN DeptInfo dept
        ON dept.DeptId = users.DeptID
           AND dept.DelFlag = 0
WHERE users.IsDelete = 0
      AND users.ClientCode IS NULL;

 

以上是关于select top 1关联查父级名称的主要内容,如果未能解决你的问题,请参考以下文章

两表联查 条件的问题

mysql多表联查

PHP 根据子ID递归获取父级ID,实现逐级分类导航效果

RecyclerView 内容未使用片段父级的全宽

MyBatis多表联查

三表联查