Попробуйте это ...
Сценарий таблицы и пример данных
CREATE TABLE [T1](
[bpm_no] [nvarchar](50) NULL,
[name] [nvarchar](50) NULL
)
CREATE TABLE [T2](
[bpm_no] [nvarchar](50) NULL,
[user] [nvarchar](50) NULL
)
CREATE TABLE [T3](
[bpm_no] [nvarchar](50) NULL,
[loan_os] [decimal](18, 0) NULL
)
INSERT [T1] ([bpm_no], [name]) VALUES (N'abc_0011', N'john')
INSERT [T2] ([bpm_no], [user]) VALUES (N'abc_0011', N'abc')
INSERT [T2] ([bpm_no], [user]) VALUES (N'abc_0011', N'bcd')
INSERT [T2] ([bpm_no], [user]) VALUES (N'abc_0011', N'lmn')
INSERT [T3] ([bpm_no], [loan_os]) VALUES (N'abc_0011', CAST(14500 AS Decimal(18, 0)))
INSERT [T3] ([bpm_no], [loan_os]) VALUES (N'abc_0011', CAST(4000 AS Decimal(18, 0)))
INSERT [T3] ([bpm_no], [loan_os]) VALUES (N'abc_0011', CAST(5000 AS Decimal(18, 0)))
Запрос
SELECT t1.bpm_no,
sq1.[user],
sq2.loan_os
FROM t1
INNER JOIN (SELECT bpm_no,
Stuff((SELECT ', ' + [user]
FROM t2 t21
WHERE t21.bpm_no = t22.bpm_no
FOR xml path('')), 1, 2, '') AS [user]
FROM t2 t22
GROUP BY bpm_no) sq1
ON t1.bpm_no = sq1.bpm_no
INNER JOIN (SELECT bpm_no,
Sum(loan_os) AS loan_os
FROM t3
GROUP BY bpm_no) sq2
ON t1.bpm_no = sq2.bpm_no
Примечание: Если вы хотите получить значения (включая нулевые значения) для всех bpm_no
в T1
основной таблице, используйте левое соединение вместо внутреннего соединения.
Запрос (Тот же ожидаемый результат без основной таблицы T1)
SELECT sq1.bpm_no,
sq1.[user],
sq2.loan_os
FROM (SELECT bpm_no,
Stuff((SELECT ', ' + [user]
FROM t2 t21
WHERE t21.bpm_no = t22.bpm_no
FOR xml path('')), 1, 2, '') AS [user]
FROM t2 t22
GROUP BY bpm_no) sq1
INNER JOIN (SELECT bpm_no, Sum(loan_os) AS loan_os
FROM t3
GROUP BY bpm_no) sq2
ON sq1.bpm_no = sq2.bpm_no
Вывод
+----------+---------------+---------+
| bpm_no | user | loan_os |
+----------+---------------+---------+
| abc_0011 | abc, bcd, lmn | 23500 |
+----------+---------------+---------+
Демонстрация: http://www.sqlfiddle.com/#!18/b6362/2/0
Если меня неправильно поняли, пожалуйста, дайте мне знать.