0

I have two tables,

First: Cars ID(primary),Name

Second : Sold ID(primary),CarID,Price,SoldUnits

How i can query to get car name where (Price * SoldUnits) is maximum?

4

1 回答 1

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
于 2013-06-11T13:35:16.667 回答