SQL Server将自己的查询结果作为待查询数据子列之

   嵌套子查询是SQL语句中比较常用的一种查询方法,开发过程中遇到查询需要将自己的某列作为待查询的数据,在参考别人的SQL语句的写法终于实现了自己需要的功能。

        查询语句如下:

        SELECT DISTINCT dbo.a.ProxyID, dbo.a.account AS adminAccount, dbo.b.LevelName, dbo.a.ProfitProportion, dbo.a.totalUpScore, dbo.a.score, dbo.a.members, dbo.a.authority, dbo.a.registerDate, dbo.a.freezeState, temp.belongName

FROM dbo.a INNER JOIN dbo.b ON dbo.a.ProxyLevel = dbo.b.LevelId INNER JOIN (SELECT   dbo.c.BelongsAgent, a.ProxyID, a.account AS belongName FROM dbo.a AS a INNER JOIN dbo.c ON a.ProxyID = BelongsAgent AND a.ProxyID = dbo.c.BelongsAgent) AS temp ON dbo.a.belongsAgent = temp.BelongsAgent

        查询结果如下:

        图片 1

        参考:http://blog.csdn.net/u013105439/article/details/65107129

 

本文由金沙官网线上发布于数据库,转载请注明出处:SQL Server将自己的查询结果作为待查询数据子列之

您可能还会对下面的文章感兴趣: