-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptimize_sql_query.sql
More file actions
283 lines (214 loc) ยท 12 KB
/
optimize_sql_query.sql
File metadata and controls
283 lines (214 loc) ยท 12 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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
SELECT * FROM hitit.fund_stocks;
show create table fund_stocks;
drop table fund_stocks;
drop table fund_bonds;
CREATE TABLE `fund_stocks` (
`fund_code` varchar(255) NOT NULL COMMENT 'ํ๋์ฝ๋',
`stock_name` varchar(255) NOT NULL COMMENT '์ฃผ์์ข
๋ชฉ๋ช
',
`size` varchar(255) DEFAULT NULL COMMENT '์ฃผ์๊ตฌ๋ถ_๊ท๋ชจ',
`style` varchar(255) DEFAULT NULL COMMENT '์ฃผ์๊ตฌ๋ถ_์คํ์ผ',
`weight` float DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `fund_bonds` (
`fund_code` varchar(255) NOT NULL COMMENT 'ํ๋์ฝ๋',
`bond_name` varchar(255) NOT NULL COMMENT '์ฑ๊ถ์ข
๋ชฉ๋ช
',
`expire_date` date DEFAULT NULL COMMENT '๋ง๊ธฐ์ผ์',
`duration` float DEFAULT NULL COMMENT '๋๋ ์ด์
',
`credit` float DEFAULT NULL COMMENT '์ ์ฉ๋ฑ๊ธ',
`weight` float DEFAULT NULL,
PRIMARY KEY (`fund_code`,`bond_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
show create table fund_stocks;
CREATE TABLE `fund_stocks` (
`fund_code` varchar(255) NOT NULL COMMENT 'ํ๋์ฝ๋',
`stock_name` varchar(255) NOT NULL COMMENT '์ฃผ์์ข
๋ชฉ๋ช
',
`size` varchar(255) DEFAULT NULL COMMENT '์ฃผ์๊ตฌ๋ถ_๊ท๋ชจ',
`style` varchar(255) DEFAULT NULL COMMENT '์ฃผ์๊ตฌ๋ถ_์คํ์ผ',
`weight` float DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
show create table fund_bonds;
CREATE TABLE `fund_bonds` (
`fund_code` varchar(255) NOT NULL COMMENT 'ํ๋์ฝ๋',
`bond_name` varchar(255) NOT NULL COMMENT '์ฑ๊ถ์ข
๋ชฉ๋ช
',
`expire_date` date DEFAULT NULL COMMENT '๋ง๊ธฐ์ผ์',
`duration` float DEFAULT NULL COMMENT '๋๋ ์ด์
',
`credit` float DEFAULT NULL COMMENT '์ ์ฉ๋ฑ๊ธ',
`weight` float DEFAULT NULL,
PRIMARY KEY (`fund_code`,`bond_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
select * from fund_bonds;
select * from fund_stocks;
select * from user_select;
drop table user_select;
select * from user_portfolios;
show create table user_portfolios;CREATE TABLE `user_portfolios` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`investment_type` varchar(255) DEFAULT NULL,
`summary` varchar(255) DEFAULT NULL,
`minimum_subscription_fee` int unsigned DEFAULT NULL,
`stock_exposure` int unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
ALTER TABLE `user_portfolios`
ADD COLUMN `user_id` int unsigned DEFAULT NULL;
UPDATE `user_portfolios`
SET `user_id` = 1
WHERE `id` = 1;
select * from user_portfolios;
show create table user_portfolios;
select * from user_portfolios;
select * from user_portfolios_fund_products where portfolio_id = 1;
select * from fund_stocks where fund_code = "K55301B73766";
CREATE TABLE `user_portfolios` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`investment_type` varchar(255) DEFAULT NULL,
`summary` varchar(255) DEFAULT NULL,
`minimum_subscription_fee` int unsigned DEFAULT NULL,
`stock_exposure` int unsigned DEFAULT NULL,
`user_id` int unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- insert into user_portfolios values (1, "์ค๋งํธ์ธ์ด๋ฒ", "์์ ํ", "์ด ํฌํธํด๋ฆฌ์ค๋ ์ด๋ค ํฌํธํด๋ฆฌ์ค์
๋๋ค.", 100,20);
select * from user_portfolios_fund_products;
select * from user_portfolios_fund_stocks;
DELETE FROM user_portfolios_fund_products where fund_code = " 'K55101C35403";
insert into user_portfolios_fund_products values
("K55101B47624", 1, "์ ํ๋๋๋ฆผ๋ฌ์์์ฆ๊ถ๋ชจํฌ์์ ํ[์ฃผ์]", "ํด์ธ์ฃผ์ํ", "์ ํ์์ฐ์ด์ฉ", 15, 4.31);
insert into user_portfolios_fund_products values
("K55301B73766", 1, "๋ฏธ๋์์
TIGERํ์ฅํ์ฆ๊ถ์์ฅ์ง์ํฌ์์ ํ(์ฃผ์)", "๊ตญ๋ด์ฃผ์ํ", "๋ฏธ๋์์
์์ฐ์ด์ฉ", 20, 59.12);
select * from fund_stocks;
select * from stocks_products;
select count(*) from stocks_products where sentiment = 0;
select * from stocks_products;
select * from user_portfolios;
select * from user_portfolios_fund_products;
select * from user_portfolios;
UPDATE `user_portfolios_fund_products`
SET `weight` = 15
WHERE `fund_code` = "K55101B46238";
select * from fund_bonds;
select * from fund_stocks;
select * from fund_assets;
select count(*) from fund_assets;
show create table fund_stocks;
drop table fund_assets;
show create table fund_assets;
CREATE TABLE `fund_assets` (
`fund_code` varchar(255) NOT NULL,
`stock` float DEFAULT NULL,
`stock_foreign` float DEFAULT NULL,
`bond` float DEFAULT NULL,
`bond_foreign` float DEFAULT NULL,
`investment` float DEFAULT NULL,
`etc` float DEFAULT NULL,
PRIMARY KEY (`fund_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
select * from fund_assets;
select count(*) from fund_assets;
show create table fund_assets;
CREATE TABLE `fund_assets` (
`fund_code` varchar(255) NOT NULL,
`stock` float DEFAULT NULL,
`stock_foreign` float DEFAULT NULL,
`bond` float DEFAULT NULL,
`bond_foreign` float DEFAULT NULL,
`investment` float DEFAULT NULL,
`etc` float DEFAULT NULL,
PRIMARY KEY (`fund_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
drop table fund_assets;
show create table fund_products_4;
CREATE TABLE `fund_products_4` (
`fund_code` varchar(255) DEFAULT NULL,
`fund_name` varchar(255) DEFAULT NULL,
`hashtag` varchar(255) DEFAULT NULL,
`std_price` float DEFAULT NULL,
`set_date` date DEFAULT NULL,
`fund_type` varchar(255) DEFAULT NULL,
`fund_type_detail` varchar(255) DEFAULT NULL,
`set_amount` int DEFAULT NULL,
`company_name` varchar(255) DEFAULT NULL,
`risk_grade` int DEFAULT NULL,
`risk_grade_txt` varchar(255) DEFAULT NULL,
`drv_nav` float DEFAULT NULL,
`bond` float DEFAULT NULL,
`bond_foreign` float DEFAULT NULL,
`stock` float DEFAULT NULL,
`stock_foreign` text,
`investment` float DEFAULT NULL,
`etc` float DEFAULT NULL,
`return_1m` float DEFAULT NULL,
`return_3m` float DEFAULT NULL,
`return_6m` float DEFAULT NULL,
`return_1y` float DEFAULT NULL,
`return_3y` float DEFAULT NULL,
`return_5y` float DEFAULT NULL,
`return_idx` float DEFAULT NULL,
`return_ytd` float DEFAULT NULL,
`arima_price` double DEFAULT NULL,
`arima_update` date DEFAULT NULL,
`arima_percent` double DEFAULT NULL,
`stock_ratio` float DEFAULT NULL,
`bond_ratio` float DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
select * from fund_products_4;
ALTER TABLE `fund_products_4`
ADD PRIMARY KEY (`fund_code`);
select count(*) from fund_products_4;
ALTER TABLE `fund_products_4`
MODIFY COLUMN `stock_foreign` FLOAT;
select * from user_portfolios;
select * from user_portfolios_fund_products;
select * from user_portfolios_fund_bonds;
select * from user_portfolios_fund_stocks;
select * from user_portfolios_fund_assets;
select * from fund_assets;
drop table user_portfolios_fund_bonds;
select * from private_portfolios;
select * from private_portfolios_fund_products;
show create table user_portfolios;
select * from user_portfolios_fund_products;
select * from fund_products_4 where fund_name = "์ ํ";
SELECT * FROM fund_products_4
WHERE fund_name LIKE '์ ํ%' and fund_type_detail = "ํด์ธ์ฃผ์ํ";
select * from fund_bonds where fund_code = "K55210BT7106";
-- K55210BT7106
select * from private_portfolios;
select * from private_portfolios_fund_products;
DELETE FROM private_portfolios_fund_products
WHERE fund_code = '2117610';
Delete from private_portfolios_fund_assets where fund_code = '2117610';
Delete from private_portfolios_fund_stocks where fund_code = '2117610';
Delete from private_portfolios_fund_bonds where fund_code = '2117610';
delete from user_portfolios_fund_products where fund_code = 'K55210BT7106';
select fund_code, fund_name, fund_type_detail, company_name, return_3m from fund_products_4 where fund_code = "K55210BT7106";
insert into user_portfolios_fund_products values
("K55101B47624", 1, "์ ํ๋๋๋ฆผ๋ฌ์์์ฆ๊ถ๋ชจํฌ์์ ํ[์ฃผ์]", "ํด์ธ์ฃผ์ํ", "์ ํ์์ฐ์ด์ฉ", 15, 4.31);
insert into private_portfolios_fund_products values
("K55210BT7106", 3, "์ ํํดํผ๋ผ์ดํ์ฐ๊ธ์ค๊ตญ๋ณธํ ์ค์ํ์ฃผ์ฆ๊ถ์ํฌ์์ ํ 1(H)[์ฃผ์](์ข
๋ฅC-re)", "ํด์ธ์ฃผ์ํ", "์ ํ์์ฐ์ด์ฉ", 25, 1.14);
select * from private_portfolios;
select * from user_portfolios;
select * from user_portfolios_fund_products;
select * from private_portfolios_fund_products;
select * from private_portfolios;
Delete from user_portfolios_fund_products where fund_code = "K55207BU0715";
insert into user_portfolios_fund_products values
("K55301B73766", 1, "๋ฏธ๋์์
TIGERํ์ฅํ์ฆ๊ถ์์ฅ์ง์ํฌ์์ ํ(์ฃผ์)", "๊ตญ๋ด์ฃผ์ํ", "๋ฏธ๋์์
์์ฐ์ด์ฉ", 20, 59.12);
select * from fund_products_4;
select * from fund_products_4 where fund_code = "K55213BU7688";
insert into fund_products_4 values
('K55207BU0715', '๊ต๋ณด์
์ฌํ์์ธ๋ฑ์ค์ฆ๊ถ์ํฌ์์ ํ 1(์ฃผ์)ClassC-Pe', '#๊ตญ๋ด์ฃผ์ํ#ํด์ง์ฐ๊ธ', '1329.14', '2017-08-14', '์ธ๋ฑ์ค์ฃผ์์ฝ์คํผ200', '๊ตญ๋ด์ฃผ์ํ', '840', '๊ต๋ณด์
์ฌ์์ฐ์ด์ฉ', '2', '๋์ ์ํ', '3757.42', '0', '0', '87.97', '0.12', '3.76', '8.15', '1.85', '5.18', '11.52', '11.73', '-6.94', '55.96', '45.99', '6.2', null, null, null, null, null);
insert into fund_products_4 values
('K55214CD4825', '์ ์ง์ฑํผ์ธ์ค๋จ๊ธฐ์ฑ์ฆ๊ถ์ํฌ์์ ํ(์ฑ๊ถ)ClassC-Re', '#๊ตญ๋ด์ฑ๊ถํ#ํด์ง์ฐ๊ธ', '1080', '2018-10-17', '์ผ๋ฐ์ฑ๊ถ', '๊ตญ๋ด์ฑ๊ถํ', '387', '์ ์ง์์ฐ์ด์ฉ', '5', '๋ฎ์ ์ํ', '2049.54', '58.28', '0', '0', '0.00', '0.06', '41.66', '0.59', '1.45', '2.75', '5.71', '9.79', '13.6', '16.21', '2.43', null, null, null, null, null);
insert into fund_products_4 values
('K55223BV4542', 'KB์ค๊ตญ๋ณธํ A์ฃผ์ฆ๊ถ์ํฌ์์ ํ(์ฃผ์)C-ํด์งe', '#ํด์ธ์ฃผ์ํ#ํด์ง์ฐ๊ธ#์ค๊ตญ', '1085.17', '2017-09-06', '์ค๊ตญ์ฃผ์', 'ํด์ธ์ฃผ์ํ', '514', '์ผ์ด๋น์์ฐ์ด์ฉ', '2', '๋์ ์ํ', '4651.17', '0', '0', '0', '84.95', '15.67', '0', '-1.97', '2.2', '1.06', '-11.07', '-34.49', '12.27', '8.52', '0.22', null, null, null, null, null);
insert into fund_products_4 values
('K55235BW6864', 'ํผ๋ธ๋ฆฌํฐ๊ธ๋ก๋ฒ๋ฐฐ๋น์ธ์ปด์ฆ๊ถ์ํฌ์์ ํ(์ฃผ์-์ฌ๊ฐ์ ํ)์ข
๋ฅCP-e', '#ํด์ธ์ฃผ์ํ#ํด์ง์ฐ๊ธ#์ธ์ปด#๋ฐฐ๋น์ฃผํ๋#๊ธ๋ก๋ฒ', '1606.61', '2017-09-20', '๊ธ๋ก๋ฒ์ฃผ์', 'ํด์ธ์ฃผ์ํ', '1285', 'ํผ๋ธ๋ฆฌํฐ์์ฐ์ด์ฉ', '2', '๋์ ์ํ', '9072.9', '0', '0', '0', '', '0', '0', '-1.99', '2.52', '7.98', '11.64', '17.39', '42.41', '63.88', '7.33', null, null, null, null, null);
insert into fund_products_4 values
('K55301BT7965', '๋ฏธ๋์์
ํด์งํ๋๊ธ๋ก๋ฒ๋ค์ด๋๋ฏน์ฆ๊ถ์ํฌ์์ ํ 1(์ฑ๊ถ)์ข
๋ฅC-P2e', '#ํด์ธ์ฑ๊ถํ#ํด์ง์ฐ๊ธ#๊ธ๋ก๋ฒ', '957.27', '2017-08-03', '๊ธ๋ก๋ฒ์ฑ๊ถ', 'ํด์ธ์ฑ๊ถํ', '1104', '๋ฏธ๋์์
์์ฐ์ด์ฉ', '5', '๋ฎ์ ์ํ', '2908.53', '7.81', '33.33', '0', '0.00', '5.86', '53', '0.49', '1.17', '1.51', '4.13', '-3.87', '2.26', '6.2', '1.02', null, null, null, null, null);
insert into fund_products_4 values
('K55370BU1789', 'AB๋ฏธ๊ตญ๊ทธ๋ก์ค์ฆ๊ถํฌ์์ ํ(์ฃผ์-์ฌ๊ฐ์ ํ)์ข
๋ฅํCe-P2', '#ํด์ธ์ฃผ์ํ#ํด์ง์ฐ๊ธ#๋ถ๋ฏธ', '2579.83', '2017-08-04', '๋ถ๋ฏธ์ฃผ์', 'ํด์ธ์ฃผ์ํ', '2138', '์ผ๋ผ์ด์ธ์ค๋ฒ์คํด์์ฐ์ด์ฉ', '2', '๋์ ์ํ', '20809.8', '0', '0', '0', '98.33', '0', '1.67', '5.19', '7.12', '20.47', '29.39', '24.38', '100.64', '157.98', '19.03', null, null, null, null, null);
insert into fund_products_4 values
('K55213BU7688', 'ํํ์ฝ๋ฆฌ์๋ฐธ๋ฅ์ฑ๊ถ์ฆ๊ถ์ํฌ์์ ํ(์ฑ๊ถ)์ข
๋ฅC-RPe(ํด์ง์ฐ๊ธ)', '#๊ตญ๋ด์ฑ๊ถํ#ํด์ง์ฐ๊ธ', '1058.52', '2017-08-17', 'ํ์ฌ์ฑ๊ถ', '๊ตญ๋ด์ฑ๊ถํ', '117', 'ํํ์์ฐ์ด์ฉ', '3', '๋ค์ ๋์ ์ํ', '1000', '84.39', '0', '0', '0', '12.59', '3.02', '0.66', '1.38', '2.83', '5.82', '7.49', '10.74', '10.1', '10.1' , null, null, null, null, null);