0% found this document useful (0 votes)
131 views3 pages

Adventure Works

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views3 pages

Adventure Works

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Use AdventureWorks2022

Go
/
***********************************************************************************
*******/
/* Categorías */
Select C.ProductCategoryID, C.Name
from Production.ProductCategory C
Order By C.ProductCategoryID Asc
Go
/
***********************************************************************************
*******/
/* Empleado */
Select HE.BusinessEntityID, HE.JobTitle, PP.FirstName, PP.LastName
From Sales.SalesPerson E
Inner Join HumanResources.Employee HE On HE.BusinessEntityID = E.BusinessEntityID
Inner Join Person.Person PP On PP.BusinessEntityID = HE.BusinessEntityID
Order By HE.BusinessEntityID Asc
Go
/
***********************************************************************************
*******/
/* Producto */
Select P.ProductID, P.Name
From Production.Product P
Order By P.ProductID Asc
Go
/
***********************************************************************************
*******/
/* Territorio */
Select T.TerritoryID, T.Name
From Sales.SalesTerritory T
Order By T.TerritoryID Asc
Go
/
***********************************************************************************
*******/
/* Tiempo */
Select Distinct Month(S.OrderDate) As Mes, Year(S.OrderDate) As Anio
From Sales.SalesOrderHeader S
Order By 1 Asc, 2 Asc
Go
/
***********************************************************************************
*******/
/* Ventas */
Select SP.BusinessEntityID, P.ProductID, PC.ProductCategoryID, T.TerritoryID,
Month(S.OrderDate) As Mes,
Year(S.OrderDate) As Anio, Sum (D.UnitPrice * D.OrderQty) As Monto
From Sales.SalesOrderHeader S
Inner Join Sales.SalesOrderDetail D On S.SalesOrderID = D.SalesOrderID
Inner Join Production.Product P On P.ProductID = D.ProductID
Inner Join Sales.SalesTerritory T On T.TerritoryID = S.TerritoryID
Inner Join Sales.SalesPerson SP On SP.BusinessEntityID = S.SalesPersonID
Inner Join Production.ProductCategory PC On PC.ProductCategoryID =
P.ProductSubcategoryID
Group By SP.BusinessEntityID, P.ProductID, PC.ProductCategoryID, T.TerritoryID,
Month(S.OrderDate), Year(S.OrderDate)
Order By Year(S.OrderDate) Asc, Month(S.OrderDate) Asc
Go

-----------------------------------------------------------------------------------
--------------------------

Create DataBase AdventureWorksETL


Go
Use AdventureWorksETL
Go
CREATE TABLE Dim_Categoria_D
( ProductCategoryID Int Primary Key,
Name NVarchar(50)
)
Go
CREATE TABLE Dim_Producto_D
( ProductID Int Primary Key,
Name NVarchar(50)
)
Go
CREATE TABLE Dim_Tiempo_D
( Mes Int,
Anio Int,
Constraint PK_Tiempo Primary Key (Mes, Anio)
)
Go
CREATE TABLE Dim_Territorio_D
( TerritoryID Int Primary Key,
Name NVarchar(50)
)
Go
CREATE TABLE Dim_Empleado_D
( BusinessEntityID Int Primary Key,
JobTitle NVarchar(50),
FirstName NVarchar(50),
LastName NVarchar(50)
)
Go
CREATE TABLE H_Ventas_D
( BusinessEntityID Int References Dim_Empleado_D(BusinessEntityID),
ProductID Int References Dim_Producto_D(ProductID),
ProductCategoryID Int References Dim_Categoria_D(ProductCategoryId),
TerritoryID Int References Dim_Territorio_D(TerritoryID),
Mes Int,
Anio Int,
Monto Money,
Constraint FK_Ventas_Tiempo Foreign Key (Mes, Anio) References Dim_Tiempo_D
(Mes, Anio)
)
Go

-----------------------------------------------------------------------------------
--------------------------

/*
Drop DataBase AdventureWorksETL

Drop Table H_Ventas_D


Drop Table Dim_Categoria_D
Drop Table Dim_Producto_D
Drop Table Dim_Empleado_D
Drop Table Dim_Territorio_D
Drop Table Dim_Tiempo_D

Delete From H_Ventas_D


Delete From Dim_Categoria_D
Delete From Dim_Producto_D
Delete From Dim_Empleado_D
Delete From Dim_Territorio_D
Delete From Dim_Tiempo_D

*/

You might also like