-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL Query - Financial Dashboard
193 lines (143 loc) · 4.61 KB
/
SQL Query - Financial Dashboard
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
-- SQL Query to create and import data from csv files:
-- SQL Query to create and import data from csv files:
-- 0. Create a database
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 (remember to update the file name and file location in below query)
-- 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;
-- If you are getting below error, then use the below point:
-- ERROR: date/time field value out of range: "0"
-- HINT: Perhaps you need a different "datestyle" setting.
-- Check the Data in Your CSV File: Ensure date column values are formatted correctly and are in a valid format that PostgreSQL can recognize (e.g., YYYY-MM-DD). And correct any incorrect or missing date values in the CSV file.
-- or
-- Update the Datestyle Setting: Set the datestyle explicitly for your session using the following command:
SET datestyle TO 'ISO, DMY';
-- Now, try to COPY the csv files!
-- 4. Insert additional data into SQL, using same COPY function
-- 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;
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 (remember to update the file name and file location in below query)
-- 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;
-- If you are getting below error, then use the below point:
-- ERROR: date/time field value out of range: "0"
-- HINT: Perhaps you need a different "datestyle" setting.
-- Check the Data in Your CSV File: Ensure date column values are formatted correctly and are in a valid format that PostgreSQL can recognize (e.g., YYYY-MM-DD). And correct any incorrect or missing date values in the CSV file.
-- or
-- Update the Datestyle Setting: Set the datestyle explicitly for your session using the following command:
SET datestyle TO 'ISO, DMY';
-- Now, try to COPY the csv files!
-- 4. Insert additional data into SQL, using same COPY function
-- 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;