Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 28, 2016 13:02
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 Fhernd/e21774fbd461c074d70f68bbfcd6f9a8 to your computer and use it in GitHub Desktop.
Save Fhernd/e21774fbd461c074d70f68bbfcd6f9a8 to your computer and use it in GitHub Desktop.
Ejemplo de uso de jerarquía de datos anidada. [OrtizOL]
SELECT s.BusinessEntityID AS 'ID Vendedor',
SUM(S2008.SalesQuota) AS 'Total Quota Ventas 2008',
SUM(S2007.SalesQuota) AS 'Total Quota Ventas 2007'
FROM Sales.SalesPerson AS S
LEFT OUTER JOIN Sales.SalesPersonQuotaHistory AS S2008
ON S.BusinessEntityID = S2008.BusinessEntityID
AND YEAR(S2008.QuotaDate) = 2008
LEFT OUTER JOIN Sales.SalesPersonQuotaHistory AS S2007
ON S.BusinessEntityID = S2007.BusinessEntityID
AND YEAR(s2007.QuotaDate) = 2007
GROUP BY S.BusinessEntityID;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment