无法弄清楚为什么我会收到错误:'desc'附近的语法不正确。 它说最后一行是问题还是那边......
select e.DealID,
e.TestID,
e.Quantity,
case
Description
when 'Active' then 'Positive' else e.Description
end as Description,
(SUM(e.Price * e.SalePrice) / NULLIF(SUM(e.SalePrice), 0)) as Price
from Product e
WHERE ArchiveID = @ArchiveID
group by e.TestID,
Description,
e.Quantity
order by e.TestID,
Description
答案 0 :(得分:1)
desc是一个保留字。
小组被混淆了,案件陈述可能也是如此。
答案 1 :(得分:0)
额外的逗号:
order by e.TestID,
^---here
Desc
将desc
变为“降序”,而是名为desc
的字段,这将是语法错误和无效字段名称。
答案 2 :(得分:0)
编辑:在追逐OP的代码时替换。
select e.DealID,
e.TestID,
e.Quantity,
case
Description
when 'Active' then 'Positive' else e.Description
end as Description,
(SUM(e.Price * e.SalePrice) / NULLIF(SUM(e.SalePrice), 0)) as Price
from Product e
WHERE ArchiveID = @ArchiveID
group by e.TestID, -- Added comma.
Description,
e.Quantity
order by e.TestID,
Description
答案 3 :(得分:0)