我有两张桌子,
第一:汽车 ID(主),名称
第二名:已售出 ID(主),CarID,价钱,SoldUnits
我如何查询以获取汽车名称(Price * SoldUnits)最多?
答案 0 :(得分:2)
寻找畅销车:
select top 1 c.name
from cars c
join sold s
on s.CarID = c.ID
group by
c.Name
order by
sum(Price * SoldUnits) desc
找到单一最大销售的汽车:
select top 1 c.name
from cars c
join sold s
on s.CarID = c.ID
order by
Price * SoldUnits desc