Skip to content

Instantly share code, notes, and snippets.

@bifacil
Created August 11, 2019 13:02
Show Gist options
  • Save bifacil/dcf84873b76970609993cb378ed77491 to your computer and use it in GitHub Desktop.
Save bifacil/dcf84873b76970609993cb378ed77491 to your computer and use it in GitHub Desktop.
SELECT
DimProduct.EnglishProductName AS Producto,
sum(sales.OrderQuantity) AS Unidades,
sum(sales.SalesAmount) AS Importe,
sum(sales.SalesAmount)/sum(sales.OrderQuantity) AS [Precio Medio]
FROM FactResellerSales sales
INNER JOIN DimProduct ON (sales.ProductKey=DimProduct.ProductKey)
INNER JOIN DimProductSubCategory ON (DimProduct.ProductSubcategoryKey=DimProductSubCategory.ProductSubcategoryKey)
INNER JOIN DimProductCategory ON (DimProductSubCategory.ProductCategoryKey=DimProductCategory.ProductCategoryKey)
INNER JOIN DimDate ON (sales.OrderDateKey=DimDate.DateKey)
WHERE
DimProductCategory.SpanishProductCategoryName='Bicicleta'
AND DimDate.SpanishMonthName='Enero'
AND DimDate.CalendarYear=2008
GROUP BY DimProduct.EnglishProductName
ORDER BY [Precio Medio] DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment