我正在尝试计算 order_Id 在子查询中出现的次数,然后将其显示在每个客户订单的平均值旁边。这是我尝试过的。
select person ,AVG(orderTotal) as avgOrdersValue , timesSeen
from
(
select
Customer_Id as person
,Order_Id
, SUM(total)as orderTotal
,(select COUNT(Order_Id) as timesSeen
from Orders where Customer_Id=person group by Order_Id
)
from Orders group by Customer_Id Order_Id order by person ) tablealias
group by person
这是我收到的消息:“ Msg 207, Level 16, State 1, Line 4 Invalid column name 'person'. Msg 8155, Level 16, State 2, Line 10 No column name is specified for column 4 of 'gg' . 消息 207,级别 16,状态 1,第 1 行无效的列名称“timesSeen”。 ”