-
Notifications
You must be signed in to change notification settings - Fork 0
/
SQL Query - Financial Dashboard Data.sql
90 lines (64 loc) · 1.61 KB
/
SQL Query - Financial Dashboard Data.sql
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
CREATE DATABASE ccdb;
-- 1. Create cc_detail table
CREATE TABLE cc_detail (
Client_Num INT,
Card_Category VARCHAR(20),
Annual_Fees INT,
Activation_30_Days INT,
Customer_Acq_Cost INT,
Week_Start_Date DATE,
Week_Num VARCHAR(20),
Qtr VARCHAR(10),
current_year INT,
Credit_Limit DECIMAL(10,2),
Total_Revolving_Bal INT,
Total_Trans_Amt INT,
Total_Trans_Ct INT,
Avg_Utilization_Ratio DECIMAL(10,3),
Use_Chip VARCHAR(10),
Exp_Type VARCHAR(50),
Interest_Earned DECIMAL(10,3),
Delinquent_Acc VARCHAR(5)
);
-- 2. Create cc_detail table
CREATE TABLE cust_detail (
Client_Num INT,
Customer_Age INT,
Gender VARCHAR(5),
Dependent_Count INT,
Education_Level VARCHAR(50),
Marital_Status VARCHAR(20),
State_cd VARCHAR(50),
Zipcode VARCHAR(20),
Car_Owner VARCHAR(5),
House_Owner VARCHAR(5),
Personal_Loan VARCHAR(5),
Contact VARCHAR(50),
Customer_Job VARCHAR(50),
Income INT,
Cust_Satisfaction_Score INT
);
-- 3. Copy csv data into SQL
-- copy cc_detail table
COPY cc_detail
FROM 'D:\credit_card.csv'
DELIMITER ','
CSV HEADER;
-- copy cust_detail table
COPY cust_detail
FROM 'D:\customer.csv'
DELIMITER ','
CSV HEADER;
SET datestyle TO 'ISO, DMY';
-- 4. Insert additional data into SQL
-- copy additional data (week-53) in cc_detail table
COPY cc_detail
FROM 'D:\cc_add.csv'
DELIMITER ','
CSV HEADER;
-- copy additional data (week-53) in cust_detail table (remember to update the file name and file location in below query)
COPY cust_detail
FROM 'D:\cust_add.csv'
DELIMITER ','
CSV HEADER;
---Thank You!