我有两个表:
我想获得订单数量最多的买家的姓名(在这种情况下,它将是ID为3的买家C)。
我写了以下查询:
select top 1 b.Name, sum (o.Amount) as amt from Buyers b
join Orders o on o.BuyerId = b.Id
group by Name
order by amt desc
它在结果行中给了我Name和amt。
如何从结果中排除 amt 并仅显示仅买方的名称?
答案 0 :(得分:4)
从选择中删除sum (o.Amount) as amt
并按以下顺序添加sum (o.Amount) desc
select top 1 b.Name from Buyers b
join Orders o on o.BuyerId = b.Id
group by Name
order by sum (o.Amount) desc