Skip to content

Commit e86c3fa

Browse files
committed
Docs: update mysql setup scripts
Modify CreateUsers.sql and CreateRecords.sql in setup folder.
1 parent 16ad9d6 commit e86c3fa

File tree

2 files changed

+20
-52
lines changed

2 files changed

+20
-52
lines changed

setup/CreateRecords.sql

+18-44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
create database if not exists `moneytracker`;
12
show databases;
23
use `moneytracker`;
34
show tables;
@@ -17,52 +18,25 @@ DESCRIBE `records`;
1718
-- DROP TABLE `records`;
1819

1920
INSERT INTO `records`(`user_id`, `category`, `date`, `amount`, `type`, `detail`) VALUES
20-
(1, 'Food', '2023-05-01', 49, 'Expense', '早餐'),
21-
(1, 'Food', '2023-05-01', 90, 'Expense', '午餐'),
22-
(1, 'Clothing', '2023-05-02', 1906, 'Expense', 'GU'),
23-
(1, 'Food', '2023-05-02', 100, 'Expense', '晚餐'),
24-
(1, 'Housing', '2023-05-03', 6000, 'Expense', '房租'),
25-
(1, 'Housing', '2023-05-03', 520, 'Expense', '水電費'),
26-
(1, 'Transport', '2023-05-04', 100, 'Expense', '機車加油'),
27-
(1, 'Recreation', '2023-05-06', 400, 'Expense', '電影票'),
28-
(1, 'Healthcare', '2023-05-07', 180, 'Expense', '感冒'),
29-
(1, 'Others', '2023-05-08', 572, 'Expense', '生活用品'),
30-
(1, 'Part-Time', '2023-05-10', 500, 'Income', '代寫作業'),
31-
(1, 'Investment', '2023-05-17', 1482, 'Income', '股息'),
32-
(1, 'Healthcare', '2023-05-07', 680, 'Expense', '健身房月票'),
33-
(1, 'Others', '2023-05-13', 200, 'Income', '發票中獎'),
34-
(1, 'Food', '2023-05-14', 120, 'Expense', '晚餐'),
35-
(1, 'Clothing', '2023-05-15', 590, 'Expense', 'Uniqlo'),
36-
(1, 'Food', '2023-05-15', 180, 'Expense', '午餐'),
37-
(1, 'Transport', '2023-05-12', 290, 'Expense', '回彰化'),
38-
(1, 'Transport', '2023-05-14', 290, 'Expense', '回台南'),
39-
(1, 'Education', '2023-05-18', 390, 'Expense', '誠品買書'),
40-
(1, 'Recreation', '2023-05-19', 120, 'Expense', '遊樂園門票'),
41-
(1, 'Healthcare', '2023-05-20', 80, 'Expense', '購買藥品'),
42-
(1, 'Part-Time', '2023-05-22', 200, 'Income', '代寫作業'),
43-
(1, 'Investment', '2023-05-23', 5000, 'Income', '賣股票'),
44-
(1, 'Food', '2023-05-26', 100, 'Expense', '午餐'),
45-
(1, 'Clothing', '2023-05-27', 70, 'Expense', '購物'),
46-
(1, 'Recreation', '2023-05-31', 150, 'Expense', '休閒娛樂'),
47-
(1, 'Healthcare', '2023-05-01', 120, 'Expense', '感冒'),
48-
(1, 'Others', '2023-05-02', 70, 'Expense', '生活用品'),
49-
(1, 'Investment', '2023-05-05', 500, 'Income', '投資收益'),
50-
(1, 'Others', '2023-05-07', 500, 'Expense', '刮刮樂'),
51-
(1, 'Others', '2023-05-07', 700, 'Income', '刮刮樂'),
52-
(1, 'Food', '2023-05-08', 80, 'Expense', '早餐'),
53-
(1, 'Clothing', '2023-05-09', 70, 'Expense', '蝦皮'),
54-
(1, 'Transport', '2023-05-11', 100, 'Expense', '機車加油'),
55-
(1, 'Recreation', '2023-05-13', 150, 'Expense', '扭蛋'),
56-
(1, 'Others', '2023-05-15', 299, 'Expense', '生活用品');
21+
(1, 'Food', '2024-04-01', 49, 'Expense', 'breakfast'),
22+
(1, 'Food', '2024-04-01', 90, 'Expense', 'lunch'),
23+
(1, 'Food', '2024-04-02', 100, 'Expense', 'dinner'),
24+
(1, 'Housing', '2024-04-03', 6000, 'Expense', 'rent'),
25+
(1, 'Investment', '2024-04-23', 5000, 'Income', 'sell stocks'),
26+
(1, 'Food', '2024-04-26', 100, 'Expense', 'lunch'),
27+
(1, 'Clothing', '2024-04-27', 70, 'Expense', 'Uniqlo'),
28+
(1, 'Recreation', '2024-04-18', 300, 'Expense', 'watch movie'),
29+
(1, 'Healthcare', '2024-04-01', 150, 'Expense', 'common cold'),
30+
(1, 'Others', '2024-04-02', 70, 'Expense', 'daily supplies'),
31+
(1, 'Transport', '2024-04-11', 100, 'Expense', 'refueling a scooter'),
32+
(1, 'Others', '2024-04-15', 299, 'Expense', 'daily supplies');
5733

5834

5935
-- show all records
6036
SELECT * FROM `records`;
61-
-- method 1, show Expense records of 1th user in May
62-
SELECT `record_id`,`category`,`date`,`amount`,`type`,`detail` FROM `records` WHERE `user_id`=1 AND `date` LIKE '2023-05%' AND `type` = 'Expense';
63-
-- method 2, show Expense records of 1th user in May
64-
SELECT `record_id`,`category`,`date`,`amount`,`type`,`detail` FROM `records` WHERE `user_id`=1 AND MONTH(`date`) = 5 AND YEAR(`date`) = 2023 AND `type` = 'Expense';
65-
-- update record
66-
UPDATE `records` SET `category` = 'Food', `date` = ?, `amount` = ?, `type` = 'Expense', `detail` = '晚餐' WHERE `user_id` = 1 AND `record_id` = 1;
37+
-- method 1, show Expense records of 1th user in April
38+
SELECT `record_id`,`category`,`date`,`amount`,`type`,`detail` FROM `records` WHERE `user_id`=1 AND `date` LIKE '2024-04%' AND `type` = 'Expense';
39+
-- method 2, show Expense records of 1th user in April
40+
SELECT `record_id`,`category`,`date`,`amount`,`type`,`detail` FROM `records` WHERE `user_id`=1 AND MONTH(`date`) = 4 AND YEAR(`date`) = 2024 AND `type` = 'Expense';
6741
-- calculate the amount of specific user with specific type and data range
68-
SELECT SUM(`amount`) FROM `records` WHERE `user_id`=1 AND MONTH(`date`) = 5 AND YEAR(`date`) = 2023 AND `type` = 'Expense' AND `category` = 'Food';
42+
SELECT SUM(`amount`) FROM `records` WHERE `user_id`=1 AND MONTH(`date`) = 4 AND YEAR(`date`) = 2024 AND `type` = 'Expense' AND `category` = 'Food';

setup/CreateUsers.sql

+2-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,8 @@ CREATE TABLE if not exists `users`(
1414
DESCRIBE `users`;
1515
-- DROP TABLE `users`;
1616

17-
INSERT INTO `users` VALUES(NULL, 'admin', '[email protected]', '0988888888', '8888');
18-
INSERT INTO `users` VALUES(NULL, 'test', '[email protected]', 0912345678, '1234');
19-
INSERT INTO `users` VALUES(NULL, 'john', '[email protected]', '0914856247', '1111');
20-
17+
INSERT INTO `users` VALUES(NULL, 'demo', '[email protected]', '0988888888', '8888');
2118

2219
-- show all users
2320
SELECT * FROM `users`;
24-
SELECT * FROM `users` WHERE `name`='admin' AND `password`='8888';
25-
26-
27-
21+
SELECT * FROM `users` WHERE `name`='demo' AND `password`='8888';

0 commit comments

Comments
 (0)