Я получаю ошибку SQL msg 116, уровень 16, состояние 1, строка 7 с этим запросом, который я пишу
Я получаю ошибку "только одно выражение может быть указано в списке выбора, когда подзапрос не введен с EXISTS." с этим запросом. Я понимаю, что это как-то связано с внутренним соединением, но я не знаю, как это исправить.
SELECT (Grp.name) AS Wayside, (Grp.state) AS ST, ( select 'G' + SUBSTRING(CONVERT(VARCHAR(100), CAST(wea AS DECIMAL (38, 2))), 3, 3) + '/' + SUBSTRING(CONVERT(VARCHAR(100), CAST(WEA AS DECIMAL (38,2))),6,3) , Base1 AS 'Primary', AVG(ssi1) OVER (PARTITION BY wea,Base1, CONVERT(DATE,Date_time)) as Primary_SSI FROM RT_Group_Status ) AS 'Group_ID', (SELECT [Name] + ',' + [State] FROM [nms_cfg4].[dbo].[Base_Equipment] WHERE Base_Equip_Address = (SELECT TOP 1 Base_Equip_Address FROM [nms_cfg4].[dbo].[be_xref_oa] WHERE x_pbase = master.dbo.ufnStringToPbase([base1]) ) ) + '(' + [base1] + ')' AS 'Primary', ( SELECT [Name] + ',' + [State] FROM [nms_cfg4].[dbo].[Base_Equipment] WHERE Base_Equip_Address = (SELECT TOP 1 Base_Equip_Address FROM [nms_cfg4].[dbo].[be_xref_oa] WHERE x_pbase = master.dbo.ufnStringToPbase([base2]) ) ) + '(' + [base2] + ')' AS 'Secondary' FROM [nms_rt].[dbo].[RT_Group_Status] AS Cov INNER JOIN [nms_cfg4].[dbo].[ATCS_Group] As Grp ON Grp.Group_Address = Cov.[WEA] ORDER BY Wayside
Что я уже пробовал:
Это мой исходный запрос, который работает; я пытаюсь добавить усреднение одного столбца к этому запросу.
SELECT ( Grp.name ) AS Wayside, ( Grp.state ) AS ST, ( SELECT 'G' + SUBSTRING(CONVERT(VARCHAR(100), CAST(WEA AS DECIMAL(38, 2))), 3, 3) + '/' + SUBSTRING(CONVERT(VARCHAR(100), CAST(WEA AS DECIMAL(38, 2))), 6, 3) ) AS 'Group_ID', ( SELECT [Name] + ',' + [State] FROM [nms_cfg4].[dbo].[Base_Equipment] WHERE Base_Equip_Address = ( SELECT TOP 1 Base_Equip_Address FROM [nms_cfg4].[dbo].[be_xref_oa] WHERE x_pbase = master.dbo.ufnStringToPbase([base1]) ) ) + ' ( ' + [base1] + ')' AS 'Primary', CAST(Cov.Average_SSI1 as VARCHAR(3)) as 'Primary_SSI', ( SELECT [Name] + ',' + [State] FROM [nms_cfg4].[dbo].[Base_Equipment] WHERE Base_Equip_Address = ( SELECT TOP 1 Base_Equip_Address FROM [nms_cfg4].[dbo].[be_xref_oa] WHERE x_pbase = master.dbo.ufnStringToPbase([base2]) ) ) + ' ( ' + [base2] + ')' AS 'Secondary', CAST(Cov.Average_SSI2 as VARCHAR(3)) as 'Secondary_SSI', CAST([Date_Time] AS DATE) AS Date FROM [NMS_RT].[dbo].[RT_Group_Average] AS Cov INNER JOIN [nms_cfg4].[dbo].[ATCS_Group] AS Grp ON Grp.Group_Address = Cov.[WEA] WHERE Date_Time >= DATEADD(DAY, -1, GETDATE()) ORDER BY Date, Wayside
Спасибо,