我有3张桌子:
Salesperson
1)ID
2)Name
3)Age
4)Salary
Customer
1)ID
2)Name
3)City
4)IndustryType
Orders
1)Number
2)Order_date
3)cust_id
4)salesperson_id
5)Amount
这就是问题所在:找到每个销售人员的最大订单金额和相关的订单号,以及该订单所属的客户。
在实施此
Select salesperson_id,Numbers As ordernum,Amount
from dbo.Orders As Ord Inner Join
(
Select salesperson_id,Max(Amount) as MaxOrder
from dbo.Orders
group by salesperson_id
) as TopOrder
on TopOrder.salesperson_id = Ord.salesperson_id
where TopOrder.MaxOrder=Ord.Amount
但它显示一个错误:
Msg 209, Level 16, State 1, Line 1
Ambiguous column name 'salesperson_id'.