-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtableauModelViewsQuery.sql
More file actions
78 lines (64 loc) · 1.63 KB
/
tableauModelViewsQuery.sql
File metadata and controls
78 lines (64 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
USE AdventureWorksDW2017;
GO
CREATE SCHEMA analytics;
GO
SELECT TOP 10 * From dbo.DimDate
GO
CREATE OR ALTER VIEW analytics.dim_date
AS
SELECT DateKey as DIM_DateId
,FullDateAlternateKey as FullDate
,CalendarYear
,EnglishMonthName as CalendarMonthName
,CalendarQuarter
,CalendarSemester
,FiscalYear
,FiscalQuarter
,FiscalSemester
FROM dbo.DimDate
GO
CREATE OR ALTER VIEW analytics.dim_product
AS
SELECT p.ProductKey as DIM_ProductId
,p.EnglishProductName as [Name]
,pc.EnglishProductCategoryName as Category
,psc.EnglishProductSubcategoryName as SubCategory
FROM dbo.DimProduct as p
JOIN dbo.DimProductSubcategory as psc
ON p.ProductSubcategoryKey = psc.ProductSubcategoryKey
JOIN dbo.DimProductCategory as pc
ON pc.ProductCategoryKey = psc.ProductCategoryKey
GO
CREATE OR ALTER VIEW analytics.dim_customer
AS
SELECT c.CustomerKey as DIM_CustomerId
,c.FirstName
,c.LastName
,c.BirthDate
,c.Gender
,g.EnglishCountryRegionName as Country
FROM dbo.DimCustomer as c
JOIN dbo.DimGeography as g
ON c.GeographyKey = g.GeographyKey
GO
CREATE OR ALTER VIEW analytics.dim_sales_territory
AS
SELECT SalesTerritoryKey as DIM_SalesTerritoryId
,SalesTerritoryGroup as SalesGroup
,SalesTerritoryCountry as Country
,SalesTerritoryRegion as Region
FROM dbo.DimSalesTerritory
GO
CREATE OR ALTER VIEW analytics.fact_internet_sales
AS
SELECT ProductKey as DIM_ProductId
,OrderDateKey as DIM_OrderDateId
,ShipDateKey as DIM_ShipDateId
,DueDateKey as DIM_DueDateId
,CustomerKey as DIM_CustomerId
,SalesTerritoryKey as DIM_SalesTerritoryId
,UnitPrice
,OrderQuantity
,SalesAmount
FROM dbo.FactInternetSales
GO