-
Notifications
You must be signed in to change notification settings - Fork 1
/
stocks.sql
207 lines (179 loc) · 4.92 KB
/
stocks.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
Create table bitcoin(
Date date Not Null,
Open float Not Null,
High float Not Null,
Low float Not Null,
Close float Not Null,
Percent_Change float not Null);
Select * from bitcoin
Create table ethereum(
Date date Not Null,
Open float Not Null,
High float Not Null,
Low float Not Null,
Close float Not Null,
Percent_Change float Not Null);
Select * from ethereum
Create table doge(
Date date Not Null,
Open float Not Null,
High float Not Null,
Low float Not Null,
Close float Not Null,
Percent_Change float Not Null);
Select * from doge
CREATE TABLE "meta" (
"Date" date NOT NULL,
"Open" float NOT NULL,
"High" float NOT NULL,
"Low" float NOT NULL,
"Close" float NOT NULL,
"Percent_Change" float NOT NULL,
CONSTRAINT "pk_meta" PRIMARY KEY (
"Date"
)
);
CREATE TABLE "msft" (
"Date" date NOT NULL,
"Open" float NOT NULL,
"High" float NOT NULL,
"Low" float NOT NULL,
"Close" float NOT NULL,
"Percent_Change" float NOT NULL,
CONSTRAINT "pk_msft" PRIMARY KEY (
"Date"
)
);
CREATE TABLE "goog" (
"Date" date NOT NULL,
"Open" float NOT NULL,
"High" float NOT NULL,
"Low" float NOT NULL,
"Close" float NOT NULL,
"Percent_Change" float NOT NULL,
CONSTRAINT "pk_goog" PRIMARY KEY (
"Date"
)
);
CREATE TABLE "aapl" (
"Date" date NOT NULL,
"Open" float NOT NULL,
"High" float NOT NULL,
"Low" float NOT NULL,
"Close" float NOT NULL,
"Percent_Change" float NOT NULL,
CONSTRAINT "pk_aapl" PRIMARY KEY (
"Date"
)
);
CREATE TABLE "nflx" (
"Date" date NOT NULL,
"Open" float NOT NULL,
"High" float NOT NULL,
"Low" float NOT NULL,
"Close" float NOT NULL,
"Percent_Change" float NOT NULL,
CONSTRAINT "pk_nflx" PRIMARY KEY (
"Date"
)
);
CREATE TABLE "amzn" (
"Date" date NOT NULL,
"Open" float NOT NULL,
"High" float NOT NULL,
"Low" float NOT NULL,
"Close" float NOT NULL,
"Percent_Change" float NOT NULL,
CONSTRAINT "pk_amzn" PRIMARY KEY (
"Date"
)
);
--------------------------------------------
--Data Cleaning for the mapping section
CREATE TABLE countries_coordinates (
"Countries" TEXT Primary Key NOT NULL,
"Latitude" NUMERIC(8, 6),
"Longitude" NUMERIC(9, 6),
"A2_ISO" TEXT
);
CREATE TABLE "Crypto_World_Countries" (
"ID" INT Primary Key Not null,
"place" INT,
"pop2023" INT NOT NULL,
"growthRate" NUMERIC(6, 5) NOT NULL,
"area" NUMERIC(9, 1),
"countries" TEXT NOT NULL,
"cca3" TEXT,
"cca2" TEXT,
"ccn3" INT,
"region" TEXT,
"subregion" TEXT,
"unMember" TEXT,
"officialName" TEXT,
"landAreaKm" NUMERIC(9, 1),
"density" NUMERIC(9, 4),
"densityMi" NUMERIC(9, 4),
"Rank" INT,
"CryptoCurrencyStatus" TEXT,
FOREIGN KEY ("countries") REFERENCES countries_coordinates ("Countries")
);
CREATE TABLE Crypto_Ownership (
"ID" INT Primary Key Not null,
"Countries" TEXT NOT NULL,
"Number_of_Crypto_Ownership" INT,
FOREIGN KEY ("Countries") REFERENCES countries_coordinates ("Countries")
);
CREATE TABLE "world_gdp_data" (
"id" INT PRIMARY KEY NOT NULL,
"pop" NUMERIC(10, 3),
"id_pop" INT,
"imfGDP" NUMERIC(20, 6),
"unGDP" NUMERIC(20, 6),
"countries" TEXT,
"gdpPerCapita" NUMERIC(13, 7),
"continent" TEXT,
"rank" INT,
FOREIGN KEY ("countries") REFERENCES countries_coordinates ("Countries")
);
CREATE TABLE "Stock_Market_Capital" (
"ID" INT Primary Key Not null,
"countries" TEXT not null,
"Total_market_cap_in_mil_US" INT not null,
"Total_market_cap_of_GDP" NUMERIC(5, 1) not null,
"Number_of_domestic_companies_listed" TEXT not null,
FOREIGN KEY ("countries") REFERENCES countries_coordinates ("Countries")
);
SELECT
cwc.countries,
countries_coordinates."Latitude",
countries_coordinates."Longitude",
cwc.pop2023,
Crypto_Ownership."Number_of_Crypto_Ownership",
world_gdp_data."gdpPerCapita"
FROM
"Crypto_World_Countries" AS cwc
LEFT JOIN
Crypto_Ownership ON cwc.countries = Crypto_Ownership."Countries"
LEFT JOIN
world_gdp_data ON cwc.countries = world_gdp_data.countries
LEFT JOIN
countries_coordinates ON cwc.countries = countries_coordinates."Countries"
WHERE
Crypto_Ownership."Number_of_Crypto_Ownership" IS NOT NULL;
-----------------
SELECT
cc."Countries",
cc."Latitude",
cc."Longitude",
"world_gdp_data"."imfGDP",
"world_gdp_data"."gdpPerCapita",
"Stock_Market_Capital"."Total_market_cap_of_GDP",
"Stock_Market_Capital"."Number_of_domestic_companies_listed"
FROM
countries_coordinates AS cc
LEFT JOIN
"Stock_Market_Capital" ON cc."Countries" = "Stock_Market_Capital"."countries"
LEFT JOIN
"world_gdp_data" ON cc."Countries" = "world_gdp_data"."countries"
WHERE
"Stock_Market_Capital"."Total_market_cap_of_GDP" IS NOT NULL;