-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL Query - Financial Dashboard Data.sql
98 lines (72 loc) · 2.32 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
91
92
93
94
95
96
97
-- 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;