DECLARE @VARIABLE AS BIGINT
SET @VARIABLE = Sum((Select Top 5 SUM(Quantity) FROM Orders Group by MenuItemName Order by Quantity Desc))
Print @VARIABLE
这将返回错误:
无法对包含的表达式执行聚合函数 聚合或子查询
我如何实现这一目标?
答案 0 :(得分:3)
考虑到您要在@model Identity.Controllers.myClass
@{
Layout = null;
}
@using (Html.BeginForm("createXML", "Home", FormMethod.Post))
{ @Html.ValidationSummary(true)
<div class="container-full" style="background-color:aliceblue">
<h3 class="= container">Einstellungen:</h3>
<div class="container">
@Html.TextBoxFor(x => x.p)
<input type="submit" value="Submit" />
</div>
</div>
}
中订购记录,而不仅仅是sum(Quantity)
试试这种方式
Quantity
答案 1 :(得分:1)
您可以使用select @variable =
,您应该按sum(Quantity) desc
排序。
declare @variable as bigint;
select @variable = Sum(SumQuantity)
from (
select top 5
SumQuantity=Sum(Quantity)
from Orders
group by MenuItemName
order by Sum(Quantity) desc
) as x;
print @variable;