I have to make a query where I show for each year wich shipper had the maximum total cost. My query now show for each year the total cost of each shipper. So in the result i must have a list of the years, for each year the shipper and the total cost. Thanks in advance.
select year(OrderDate), s.ShipperID, sum(freight)
from orders o
join shippers s on o.ShipVia = s.ShipperID
group by year(OrderDate),s.ShipperID
Inner query a is your original query, getting the value of freight by shipper.
Inner query max gets the max value for each year, and then query max is joined to query a, restricting the rows in a to be those with a value for a year = to the max value for the year.
Cheers -