Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select t1.Country, t1.ContactName,t1.CustomerID,t1.numeroOrdenes,
- t1.importe from
- (
- select c.Country, c.ContactName,c.CustomerID, count(o.OrderID) as numeroOrdenes,
- sum((od.UnitPrice*od.Quantity)* (1- od.Discount)) as importe,
- row_number() OVER (partition by (c.Country) order by count(o.OrderID) desc ) as indice
- from Customers as c
- inner join Orders as o
- on o.CustomerID = c.CustomerID
- inner join [Order Details] as od
- on o.OrderID = od.OrderID
- where year(o.OrderDate) = 1997 and o.ShipCountry = c.Country
- group by c.Country, c.ContactName,c.CustomerID
- )t1
- where indice = 1
- order by t1.Country, t1.numeroOrdenes desc, t1.ContactName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement