SELECT
T.[ID] AS ID,
A.UserName AS ,
T. AS ,
T. AS ,
W.[ID] AS ID,
B.UserName AS ,
W. AS ,
W. AS ,
X.[ID] AS ID,
C.UserName AS ,
X. AS ,
X. AS
FROM
(
SELECT
MX.[ID],
SUM (CONVERT ( DECIMAL ( 13, 1 ), MX.[] )) AS [],
row_number () OVER ( ORDER BY SUM ( CONVERT ( DECIMAL ( 13, 1 ), MX.[] )) DESC )
FROM
dbo.[MX_] AS MX
GROUP BY MX.[ID]
) T
LEFT JOIN (
SELECT
MX.[ID],
SUM (CONVERT ( DECIMAL ( 13, 1 ), MX.[] )) AS [],
row_number () OVER ( ORDER BY SUM ( CONVERT ( DECIMAL ( 13, 1 ), MX.[] )) DESC )
FROM
dbo.[MX_] AS MX
GROUP BY MX.[ID]
) W ON T. = W.-1
LEFT JOIN (
SELECT
MX.[ID],
SUM (CONVERT ( DECIMAL ( 13, 1 ), MX.[] )) AS [],
row_number () OVER ( ORDER BY SUM ( CONVERT ( DECIMAL ( 13, 1 ), MX.[] )) DESC )
FROM
dbo.[MX_] AS MX
GROUP BY MX.[ID]
) X ON T. = X.+1
LEFT JOIN dbo.Sys_Users as A ON T.[ID] = A.UserID
LEFT JOIN dbo.Sys_Users as B ON W.[ID] = B.UserID
LEFT JOIN dbo.Sys_Users as C ON X.[ID] = C.UserID
WHERE T.[ID] = -8191