左加入后无法分组
这是我的查询(来自触发器):
UPDATE QuoteItemsGroupFeature
SET Cost = (QuoteItemsGroup.BaseCost + QuoteItemsGroup.AccumulatedCost +
ISNULL(SUM(ParentQuoteItemsGroupFeature.Cost), 0)) * INSERTED.Amount
FROM QuoteItemsGroupFeature INNER JOIN INSERTED
ON QuoteItemsGroupFeature.QuoteItemsGroupFeatureId =
INSERTED.QuoteItemsGroupFeatureId
INNER JOIN QuoteItemsGroup ON QuoteItemsGroup.QuoteItemsGroupId =
INSERTED.QuoteItemsGroupId
LEFT OUTER JOIN QuoteItemsGroupFeature ParentQuoteItemsGroupFeature ON
ParentQuoteItemsGroupFeature.QuoteItemsGroupFeatureId =
INSERTED.ParentQuoteItemsGroupFeatureId
GROUP BY QuoteItemsGroup.BaseCost,
QuoteItemsGroup.AccumulatedCost,
INSERTED.Feature,
INSERTED.Cost
它说:
Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'GROUP'.
Here is my query (from a trigger):
UPDATE QuoteItemsGroupFeature
SET Cost = (QuoteItemsGroup.BaseCost + QuoteItemsGroup.AccumulatedCost +
ISNULL(SUM(ParentQuoteItemsGroupFeature.Cost), 0)) * INSERTED.Amount
FROM QuoteItemsGroupFeature INNER JOIN INSERTED
ON QuoteItemsGroupFeature.QuoteItemsGroupFeatureId =
INSERTED.QuoteItemsGroupFeatureId
INNER JOIN QuoteItemsGroup ON QuoteItemsGroup.QuoteItemsGroupId =
INSERTED.QuoteItemsGroupId
LEFT OUTER JOIN QuoteItemsGroupFeature ParentQuoteItemsGroupFeature ON
ParentQuoteItemsGroupFeature.QuoteItemsGroupFeatureId =
INSERTED.ParentQuoteItemsGroupFeatureId
GROUP BY QuoteItemsGroup.BaseCost,
QuoteItemsGroup.AccumulatedCost,
INSERTED.Feature,
INSERTED.Cost
It says:
Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'GROUP'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将聚合删除到派生表(或 CTE),
我认为这就是您想要的,而且我认为您的分组方式也是错误的。我还添加了别名以使其更易于阅读(无论如何对我来说)
You have to remove the aggregate to a derived table (or CTE)
I think this is what you want, and I think your group by is wrong too. I've also added aliases to make it easier to read (for me anyway)