-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW.sql
More file actions
403 lines (349 loc) · 21.4 KB
/
Copy pathHW.sql
File metadata and controls
403 lines (349 loc) · 21.4 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
-- ------------------------------------------------------
-- 免责声明:
-- 1. 本模板仅供学习与参考,使用者可根据自身需求自由修改、增删字段或调整结构。
-- 2. 因使用者自行修改或二次分发而产生的任何数据丢失、损坏或其他后果,均由修改者/分享者自行承担,与作者无关。
-- 3. 严禁使用本模板或其修改版本在竞赛、才艺展示、认证考试等以任何形式构成弄虚作假行为。如有违反,使用者自行承担一切后果。
-- 4. 作者概不承担因使用本模板或其修改版本而产生的任何直接或间接责任,亦不对任何滥用行为负责。作者不承诺提供任何形式的技术支持或后续更新,使用即代表同意以上条款。
--
-- 测试环境:MySQL dump 10.13 Distrib 8.0.28, for macos11 (x86_64)
-- 作者:AUSTIN LI
-- 若要开始使用,请先填写这份sql文件中所有“CREATE TABLE的对应字段”及“你要插入的数据”部分的内容,然后执行这些代码:
-- DROP DATABASE IF EXISTS [你想要的数据库名称];
-- CREATE DATABASE [你想要的数据库名称];
-- USE [CREATE DATABASE创建的数据库];
-- SOURCE /存放的路径/HW.sql;
-- ------------------------------------------------------
-- 测试环境:Server version 8.0.28
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table buyer_names
--
DROP TABLE IF EXISTS buyer_names;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE buyer_names (
buyer_id int NOT NULL,
buyer_name text NOT NULL,
PRIMARY KEY (buyer_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table buyer_names
--
LOCK TABLES buyer_names WRITE;
/*!40000 ALTER TABLE buyer_names DISABLE KEYS */;
INSERT INTO buyer_names(CREATE TABLE中的对应字段) VALUES (你要插入的数据);
/*!40000 ALTER TABLE buyer_names ENABLE KEYS */;
UNLOCK TABLES;
--
-- Temporary view structure for view chkstat_by_mth
--
DROP TABLE IF EXISTS chkstat_by_mth;
/*!50001 DROP VIEW IF EXISTS chkstat_by_mth*/;
SET @saved_cs_client = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW chkstat_by_mth AS SELECT
1 AS group_name,
1 AS car_count,
1 AS total_spent,
1 AS avg_price*/;
SET character_set_client = @saved_cs_client;
--
-- Temporary view structure for view chkstat_by_ser
--
DROP TABLE IF EXISTS chkstat_by_ser;
/*!50001 DROP VIEW IF EXISTS chkstat_by_ser*/;
SET @saved_cs_client = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW chkstat_by_ser AS SELECT
1 AS group_name,
1 AS car_count,
1 AS total_spent,
1 AS avg_price*/;
SET character_set_client = @saved_cs_client;
--
-- Temporary view structure for view chkstat_total
--
DROP TABLE IF EXISTS chkstat_total;
/*!50001 DROP VIEW IF EXISTS chkstat_total*/;
SET @saved_cs_client = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW chkstat_total AS SELECT
1 AS total_spent,
1 AS total_car_count*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table gift_statuses
--
DROP TABLE IF EXISTS gift_statuses;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE gift_statuses (
status_id int NOT NULL,
status_name text NOT NULL,
PRIMARY KEY (status_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table gift_statuses
--
LOCK TABLES gift_statuses WRITE;
/*!40000 ALTER TABLE gift_statuses DISABLE KEYS */;
INSERT INTO gift_statuses VALUES (0,'否'),(1,'已送出'),(2,'已收到'); -- 说明:此处“已送出”特指自己已经送给别人,“已收到”特指自己已经收到的来自他人的礼物
/*!40000 ALTER TABLE gift_statuses ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table hotwheels_cars
--
DROP TABLE IF EXISTS hotwheels_cars;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE hotwheels_cars (
car_id int NOT NULL AUTO_INCREMENT,
car_name text NOT NULL,
series_id int NOT NULL,
currency varchar(3) NOT NULL,
price_amount decimal(12,2) DEFAULT NULL,
buyer int NOT NULL DEFAULT '0',
purchase_type int NOT NULL DEFAULT '0',
th_status int NOT NULL DEFAULT '0',
chase_status tinyint(1) NOT NULL DEFAULT '0',
is_opened int NOT NULL DEFAULT '0',
is_a_gift int NOT NULL DEFAULT '0',
is_a_parcel int NOT NULL DEFAULT '0',
storage_id int NOT NULL,
created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, -- 说明:在MySQL 8.0.28版本中,DATETIME类型的字段即使DEFAULT设为NOW()也会被解析为CURRENT_TIMESTAMP
PRIMARY KEY (car_id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table hotwheels_cars
--
LOCK TABLES hotwheels_cars WRITE;
/*!40000 ALTER TABLE hotwheels_cars DISABLE KEYS */;
INSERT INTO hotwheels_cars(CREATE TABLE中的对应字段) VALUES (你要插入的数据);
/*!40000 ALTER TABLE hotwheels_cars ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table opened_statuses
--
DROP TABLE IF EXISTS opened_statuses;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE opened_statuses (
status_id int NOT NULL,
status_name text NOT NULL,
PRIMARY KEY (status_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table opened_statuses
--
LOCK TABLES opened_statuses WRITE;
/*!40000 ALTER TABLE opened_statuses DISABLE KEYS */;
INSERT INTO opened_statuses VALUES (0,'未拆封'),(1,'已拆封');
/*!40000 ALTER TABLE opened_statuses ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table parcel_statuses
--
DROP TABLE IF EXISTS parcel_statuses;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE parcel_statuses (
status_id int NOT NULL,
status_name text NOT NULL,
PRIMARY KEY (status_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table parcel_statuses
--
LOCK TABLES parcel_statuses WRITE;
/*!40000 ALTER TABLE parcel_statuses DISABLE KEYS */;
INSERT INTO parcel_statuses VALUES (0,'否'),(1,'已寄出'),(2,'在运输途中'),(3,'已收到'); -- 说明:此处“已寄出”特指自己寄给别人的快递已经寄出,“在运输途中”特指别人寄给自己的快递已经在运输途中,“已收到”特指自己已经收到别人寄过来的快递
/*!40000 ALTER TABLE parcel_statuses ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table purchase_types
--
DROP TABLE IF EXISTS purchase_types;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE purchase_types (
type_id int NOT NULL,
type_name text NOT NULL,
PRIMARY KEY (type_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table purchase_types
--
LOCK TABLES purchase_types WRITE;
/*!40000 ALTER TABLE purchase_types DISABLE KEYS */;
INSERT INTO purchase_types VALUES (0,'自购'),(1,'代购'),(2,'由别人付款'); -- 说明:此处“代购”特指由别人帮忙挑选并先行购买在收到货后再付对应货款给别人的代购模式
/*!40000 ALTER TABLE purchase_types ENABLE KEYS */;
UNLOCK TABLES;
--
-- Temporary view structure for view query
--
DROP TABLE IF EXISTS query;
/*!50001 DROP VIEW IF EXISTS query*/;
SET @saved_cs_client = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW query AS SELECT
1 AS car_id,
1 AS car_name,
1 AS series_name,
1 AS full_price,
1 AS buyer,
1 AS is_a_gift,
1 AS is_a_parcel,
1 AS purchase_type,
1 AS treasure_hunt,
1 AS chase_status,
1 AS opened_status,
1 AS storage_location,
1 AS created_at*/;
SET character_set_client = @saved_cs_client;
--
-- Table structure for table series
--
DROP TABLE IF EXISTS series;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE series (
series_id int NOT NULL AUTO_INCREMENT,
series_name text NOT NULL,
PRIMARY KEY (series_id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table series
--
LOCK TABLES series WRITE;
/*!40000 ALTER TABLE series DISABLE KEYS */;
INSERT INTO series VALUES (1,'普标'),(2,'银标'),(3,'金标');
/*!40000 ALTER TABLE series ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table storage_locations
--
DROP TABLE IF EXISTS storage_locations;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE storage_locations (
storage_id int NOT NULL AUTO_INCREMENT,
location_name text NOT NULL,
PRIMARY KEY (storage_id)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table storage_locations
--
LOCK TABLES storage_locations WRITE;
/*!40000 ALTER TABLE storage_locations DISABLE KEYS */;
INSERT INTO storage_locations(CREATE TABLE中的对应字段) VALUES (你要插入的数据);
/*!40000 ALTER TABLE storage_locations ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table treasure_hunt_statuses
--
DROP TABLE IF EXISTS treasure_hunt_statuses;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE treasure_hunt_statuses (
status_id int NOT NULL,
status_name text NOT NULL,
PRIMARY KEY (status_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table treasure_hunt_statuses
--
LOCK TABLES treasure_hunt_statuses WRITE;
/*!40000 ALTER TABLE treasure_hunt_statuses DISABLE KEYS */;
INSERT INTO treasure_hunt_statuses VALUES (0,'否'),(1,'普宝'),(2,'超宝');
/*!40000 ALTER TABLE treasure_hunt_statuses ENABLE KEYS */;
UNLOCK TABLES;
--
-- Final view structure for view chkstat_by_mth
--
/*!50001 DROP VIEW IF EXISTS chkstat_by_mth*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8mb4 */;
/*!50001 SET character_set_results = utf8mb4 */;
/*!50001 SET collation_connection = utf8mb4_0900_ai_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=root@localhost SQL SECURITY DEFINER */
/*!50001 VIEW chkstat_by_mth AS select final.group_name AS group_name, final.car_count AS car_count, final.total_spent AS total_spent, final.avg_price AS avg_price from (select combined.purchase_month AS group_name, combined.monthly_car_count AS car_count, combined.monthly_spent_by_currency AS total_spent, combined.avg_price_by_currency AS avg_price from (select monthly_currency.purchase_month AS purchase_month, sum(monthly_currency.pack_size) AS monthly_car_count, group_concat(concat(monthly_currency.currency, round(monthly_currency.monthly_spent,2)) order by monthly_currency.min_car_id ASC separator '+') AS monthly_spent_by_currency, group_concat(concat(monthly_currency.currency, round(monthly_currency.avg_price,2)) order by monthly_currency.min_car_id ASC separator '+') AS avg_price_by_currency from (select date_format(with_pack_size.created_at,'%Y-%m') AS purchase_month, with_pack_size.currency AS currency, min(with_pack_size.car_id) AS min_car_id, sum(with_pack_size.price_amount) AS monthly_spent, (sum(with_pack_size.price_amount) / sum(with_pack_size.pack_size)) AS avg_price, sum(with_pack_size.pack_size) AS pack_size from (select hotwheels_cars.car_id AS car_id, hotwheels_cars.created_at AS created_at, hotwheels_cars.currency AS currency, hotwheels_cars.price_amount AS price_amount, coalesce(cast(regexp_substr(hotwheels_cars.car_name,'[0-9]+(?=-Pack)') as unsigned),1) AS pack_size from hotwheels_cars where ((hotwheels_cars.created_at >= '2026-05-01') and (hotwheels_cars.purchase_type in (0,1)))) with_pack_size group by purchase_month, with_pack_size.currency) monthly_currency group by monthly_currency.purchase_month union all select 'Total' AS purchase_month, sum(total_currency.pack_size) AS monthly_car_count, group_concat(concat(total_currency.currency, round(total_currency.total_spent,2)) order by total_currency.min_car_id ASC separator '+') AS monthly_spent_by_currency, group_concat(concat(total_currency.currency, round(total_currency.avg_price,2)) order by total_currency.min_car_id ASC separator '+') AS avg_price_by_currency from (select total_with_pack_size.currency AS currency, min(total_with_pack_size.car_id) AS min_car_id, sum(total_with_pack_size.price_amount) AS total_spent, (sum(total_with_pack_size.price_amount) / sum(total_with_pack_size.pack_size)) AS avg_price, sum(total_with_pack_size.pack_size) AS pack_size from (select hotwheels_cars.car_id AS car_id, hotwheels_cars.currency AS currency, hotwheels_cars.price_amount AS price_amount, coalesce(cast(regexp_substr(hotwheels_cars.car_name,'[0-9]+(?=-Pack)') as unsigned),1) AS pack_size from hotwheels_cars where ((hotwheels_cars.created_at >= '2026-05-01') and (hotwheels_cars.purchase_type in (0,1)))) total_with_pack_size group by total_with_pack_size.currency) total_currency) combined) final order by (case when (final.group_name = 'Total') then 1 else 0 end), final.group_name */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view chkstat_by_ser
--
/*!50001 DROP VIEW IF EXISTS chkstat_by_ser*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8mb4 */;
/*!50001 SET character_set_results = utf8mb4 */;
/*!50001 SET collation_connection = utf8mb4_0900_ai_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=root@localhost SQL SECURITY DEFINER */
/*!50001 VIEW chkstat_by_ser AS select final.group_name AS group_name, final.car_count AS car_count, final.total_spent AS total_spent, final.avg_price AS avg_price from (select combined.series_name AS group_name, combined.car_count AS car_count, combined.total_spent_by_currency AS total_spent, combined.avg_price_by_currency AS avg_price from (select series_currency.series_name AS series_name, sum(series_currency.pack_size) AS car_count, group_concat(concat(series_currency.currency, round(series_currency.total_spent,2)) order by series_currency.min_car_id ASC separator '+') AS total_spent_by_currency, group_concat(concat(series_currency.currency, round(series_currency.avg_price,2)) order by series_currency.min_car_id ASC separator '+') AS avg_price_by_currency from (select sn.series_name AS series_name, with_pack_size.currency AS currency, min(with_pack_size.car_id) AS min_car_id, sum(with_pack_size.price_amount) AS total_spent, (sum(with_pack_size.price_amount) / sum(with_pack_size.pack_size)) AS avg_price, sum(with_pack_size.pack_size) AS pack_size from ((select m.car_id AS car_id, m.series_id AS series_id, m.currency AS currency, m.price_amount AS price_amount, coalesce(cast(regexp_substr(m.car_name,'[0-9]+(?=-Pack)') as unsigned),1) AS pack_size from hotwheels_cars m where (m.purchase_type in (0,1))) with_pack_size join series sn on((with_pack_size.series_id = sn.series_id))) group by sn.series_name, with_pack_size.currency) series_currency group by series_currency.series_name union all select 'Total' AS series_name, sum(total_currency.pack_size) AS car_count, group_concat(concat(total_currency.currency, round(total_currency.total_spent,2)) order by total_currency.min_car_id ASC separator '+') AS total_spent_by_currency, group_concat(concat(total_currency.currency, round(total_currency.avg_price,2)) order by total_currency.min_car_id ASC separator '+') AS avg_price_by_currency from (select total_with_pack_size.currency AS currency, min(total_with_pack_size.car_id) AS min_car_id, sum(total_with_pack_size.price_amount) AS total_spent, (sum(total_with_pack_size.price_amount) / sum(total_with_pack_size.pack_size)) AS avg_price, sum(total_with_pack_size.pack_size) AS pack_size from (select hotwheels_cars.car_id AS car_id, hotwheels_cars.currency AS currency, hotwheels_cars.price_amount AS price_amount, coalesce(cast(regexp_substr(hotwheels_cars.car_name,'[0-9]+(?=-Pack)') as unsigned),1) AS pack_size from hotwheels_cars where (hotwheels_cars.purchase_type in (0,1))) total_with_pack_size group by total_with_pack_size.currency) total_currency) combined) final order by (case when (final.group_name = 'Total') then 1 else 0 end), final.group_name */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view chkstat_total
--
/*!50001 DROP VIEW IF EXISTS chkstat_total*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8mb4 */;
/*!50001 SET character_set_results = utf8mb4 */;
/*!50001 SET collation_connection = utf8mb4_0900_ai_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=root@localhost SQL SECURITY DEFINER */
/*!50001 VIEW chkstat_total AS select (select group_concat(concat(currency_totals.currency, round(currency_totals.total,2)) order by currency_totals.min_car_id ASC separator '+') from (select hotwheels_cars.currency AS currency, min(hotwheels_cars.car_id) AS min_car_id, sum(hotwheels_cars.price_amount) AS total from hotwheels_cars where (hotwheels_cars.purchase_type in (0,1)) group by hotwheels_cars.currency) currency_totals) AS total_spent, (select sum(coalesce(cast(regexp_substr(hotwheels_cars.car_name,'[0-9]+(?=-Pack)') as unsigned),1)) from hotwheels_cars) AS total_car_count */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
--
-- Final view structure for view query
--
/*!50001 DROP VIEW IF EXISTS query*/;
/*!50001 SET @saved_cs_client = @@character_set_client */;
/*!50001 SET @saved_cs_results = @@character_set_results */;
/*!50001 SET @saved_col_connection = @@collation_connection */;
/*!50001 SET character_set_client = utf8mb4 */;
/*!50001 SET character_set_results = utf8mb4 */;
/*!50001 SET collation_connection = utf8mb4_0900_ai_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=root@localhost SQL SECURITY DEFINER */
/*!50001 VIEW query AS select m.car_id AS car_id, m.car_name AS car_name, s.series_name AS series_name, concat(m.currency, m.price_amount) AS full_price, b.buyer_name AS buyer, g.status_name AS is_a_gift, p.status_name AS is_a_parcel, pt.type_name AS purchase_type, th.status_name AS treasure_hunt, if(m.chase_status,'Chase Car','No') AS chase_status, op.status_name AS opened_status, st.location_name AS storage_location, m.created_at AS created_at from ((((((((hotwheels_cars m join buyer_names b on((m.buyer = b.buyer_id))) join gift_statuses g on((m.is_a_gift = g.status_id))) join parcel_statuses p on((m.is_a_parcel = p.status_id))) join purchase_types pt on((m.purchase_type = pt.type_id))) join treasure_hunt_statuses th on((m.th_status = th.status_id))) join opened_statuses op on((m.is_opened = op.status_id))) left join series s on((m.series_id = s.series_id))) left join storage_locations st on((m.storage_id = st.storage_id))) */;
/*!50001 SET character_set_client = @saved_cs_client */;
/*!50001 SET character_set_results = @saved_cs_results */;
/*!50001 SET collation_connection = @saved_col_connection */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;