Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 14, 2019 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/252d07a4176cd84d8afce36a89db4bae to your computer and use it in GitHub Desktop.
Save parzibyte/252d07a4176cd84d8afce36a89db4bae to your computer and use it in GitHub Desktop.
/*Las ventas por territorio*/
select st.Name, sum(so.OrderQty * so.UnitPrice) as total_vendido
from Sales.SalesOrderHeader sh
inner join Sales.SalesOrderDetail so
on sh.SalesOrderID = so.SalesOrderID
inner join Sales.SalesTerritory st
on st.TerritoryID = sh.TerritoryID
group by st.TerritoryID, st.Name
order by sum(so.OrderQty * so.UnitPrice) desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment