-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData Cleansing.sql
More file actions
72 lines (61 loc) · 2.5 KB
/
Data Cleansing.sql
File metadata and controls
72 lines (61 loc) · 2.5 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
-- TAB GENERALVIEW:
-- KPIS:
-- i) Total Internet Sales Amount
-- ii) Total Internet Sales
-- iii) Product Categories
-- iv) Total of Customers
-- v) Total Internet Sales Amount and Profit per month
-- vi) Total Internet Sales by Gender
-- vii) Profit Margin
-- viii) Total Sales per Month
-- ix) Profit per Country
-- Tables:
select top(5) * from FactInternetSales -- TABLE 1
select top(5) * from DimProductCategory -- TABLE 2
select top(5) * from DimGeography -- TABLE 3
select top(5) * from DimCustomer -- TABLE 4
-- TAB CLIENTS:
-- KPIS:
-- i) Sales per Country
-- ii) Customers per Country
-- iii) Sales per Gender
-- iv) Sales per Category
select top(5) * from FactInternetSales -- TABLE 1
select top(5) * from DimGeography -- TABLE 3
select top(5) * from DimCustomer -- TABLE 4
-- Columns:
-- SalesOrderNumber (TABLE 1: FactInternetSales)
-- OrderDate (TABLE 1: FactInternetSales)
-- EnglishProductCategoryName (TABLE 2: DimProductCategory)
-- CustomerKey (TABLE 1: FactInternetSales)
-- First Name + Last Name (TABLE 4: DimCustomer)
-- Gender (TABLE 4: DimCustomer)
-- EnglishCountryRegionName (TABLE 3: DimGeography)
-- OrderQuantity (TABLE 1: FactInternetSales)
-- TotalProductCost (TABLE 1: FactInternetSales)
-- SalesAmount (TABLE 1: FactInternetSales)
-- SalesAmount - TotalProductCost (Profit) (TABLE 1: FactInternetSales)
-- Creating view RESULTS_ADW
GO
CREATE OR ALTER VIEW RESULTS_ADW as
select
fis.SalesOrderNumber,
fis.OrderDate,
dpc.EnglishProductCategoryName as ProductCategory,
fis.CustomerKey,
dc.FirstName + ' ' + dc.LastName as CustomerName,
replace(replace(dc.Gender, 'M', 'Male'), 'F', 'Female') as CustomerGender,
dg.EnglishCountryRegionName as Country,
fis.OrderQuantity as SalesQuantity,
fis.SalesAmount,
fis.TotalProductCost,
fis.SalesAmount - fis.TotalProductCost as Profit
from
FactInternetSales fis
left join DimProduct dp on fis.ProductKey = dp.ProductKey
left join DimProductSubcategory dps on dp.ProductSubcategoryKey = dps.ProductSubcategoryKey
left join DimProductCategory dpc on dps.ProductCategoryKey = dpc.ProductCategoryKey
left join DimCustomer dc on fis.CustomerKey = dc.CustomerKey
left join DimGeography dg on dc.GeographyKey = dg.GeographyKey
GO
select * from RESULTS_ADW