Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. select t1.Country, t1.ContactName,t1.CustomerID,t1.numeroOrdenes,
  2. t1.importe from
  3. (
  4.  
  5. select c.Country, c.ContactName,c.CustomerID, count(o.OrderID) as numeroOrdenes,
  6. sum((od.UnitPrice*od.Quantity)* (1- od.Discount)) as importe,
  7.  
  8. row_number() OVER (partition by (c.Country) order by count(o.OrderID) desc ) as indice
  9.  
  10. from Customers as c
  11.  
  12. inner join Orders as o
  13. on o.CustomerID = c.CustomerID
  14. inner join [Order Details] as od
  15. on o.OrderID = od.OrderID
  16.  
  17. where year(o.OrderDate) = 1997 and o.ShipCountry = c.Country
  18. group by c.Country, c.ContactName,c.CustomerID
  19.  
  20. )t1
  21. where indice = 1
  22. order by t1.Country, t1.numeroOrdenes desc, t1.ContactName
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement