cte4 as (
SELECT *,
case
when roadName=roadNameUserData then sec1
else 'x'
end as roadCrossSection1
FROM dbo.roadSectionAndPavementUserData,cte3
)
--"roadName" is from cte computed column view
--"roadNameUserData" is from other table("dbo.roadSectionAndPavementUserData") where records are to be extracted
--sec1 is the column in table "dbo.roadSectionAndPavementUserData" where the results coming from
-----final view
SELECT roadName,
sum(roadLength) as sumRoadLength,roadCrossSection1
FROM cte4
group by roadName
order by roadName
当我执行查询时,出现以下错误
“列 'cte4.roadCrossSection1' 在选择列表中无效,因为它不包含在聚合函数或 GROUP BY 子句中。”
这是添加额外的 groupby 语句后的结果。正确的记录是 sumRoadLength 的较小值。