我有一个根据组件状态和可用性列出功能的查询
SELECT Brand.Id
, Brand.Name
, Brand.Impact
, Brand.Visibility
, Brand.Risk
, SUM(Brand.Impact + Brand.Visibility + Brand.Risk) AS Priority
FROM Brand
LEFT OUTER JOIN Type
ON Brand.Id = Type.FeatureId
LEFT OUTER JOIN Model
ON Type.Id = Model.SubFeatureId
LEFT OUTER JOIN TestingStatus
ON Model.StatusId = TestingStatus.Id
WHERE (Model.IsDeleted = 'False')
AND (Brand.IsDeleted = 'False')
AND (Type.IsDeleted = 'False')
AND (@TeamId = 0 OR Model.TeamId = @TeamId)
GROUP BY Brand.YearId, Brand.Id, Brand.Name, Brand.Impact, Brand.Visibility, Brand.Risk
HAVING (Brand.YearId = @YearId)
我的结果如下:
ID Name Impact Visibility Risk Priority
403 Chevy 1 2 3 48
404 Nissan 1 1 1 24
405 Toyota 3 2 1 42
代替
ID Name Impact Visibility Risk Priority
403 Chevy 1 2 3 6
404 Nissan 1 1 1 3
405 Toyota 3 2 1 6
每个品牌分别有 8、8 和 7 个型号。这意味着我的查询正在为所有人计算优先级:Impact*models + Visibility*models + Risk*models
。
我怎样才能让我的 SQL 查询不做那个乘法?
谢谢