我的代码有什么问题?如果我在最后一组之前和之后删除代码,则平均每个工作日内的销售。但我希望平均所有工作日。
select [Weekday], Avg(Amountpaid)
from (select Sum(Amountpaid), [Weekday], [Date]
from
itsthegoodtable
group by [Weekday], [Date]
)
group by [Weekday]
它不断带来错误信息
关键字组附近的语法不正确
答案 0 :(得分:1)
你快到了。您的查询缺少子查询的别名。
select [Weekday], Avg(Amountpaid)
from (select Sum(Amountpaid) as amountpaid, [Weekday], [Date] from itsthegoodtable
group by [Weekday], [Date] ) t
group by [Weekday]
答案 1 :(得分:0)
您需要为使用总和计算的值添加别名:
select [Weekday], Avg(Amountpaid) as Amountpaid
from (select Sum(Amountpaid) as Amountpaid, [Weekday], [Date]
from
itsthegoodtable
group by [Weekday], [Date]
) ap
group by [Weekday]