-
Notifications
You must be signed in to change notification settings - Fork 0
/
makedb
38 lines (26 loc) · 1.59 KB
/
makedb
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
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation
mysql -uroot -p
CREATE DATABASE budget;
GRANT ALL PRIVILEGES ON budget.* TO 'budgetmaker'@'localhost';
exit;
mysql -h budgetwatcher.clz6jgg0hiys.us-east-1.rds.amazonaws.com -P3306 -u budgetwatcher -p budgetwatcher
Schofieldbw
mysql -ubudgetmaker budget
DROP TABLE IF EXISTS transactions;
CREATE TABLE transactions (id INT PRIMARY KEY AUTO_INCREMENT NOT NULL, account TINYINT, date DATE, cents INT, title TINYBLOB);
INSERT INTO transactions VALUES (NULL, 1, '2016-06-03', 534, 'five dollars');
INSERT INTO transactions VALUES (NULL, 1, '2016-06-02', 601, 'six dollars');
INSERT INTO transactions VALUES (NULL, 1, '2016-06-01', 742, 'seven dollars');
INSERT INTO transactions VALUES (NULL, 2, '2016-06-01', 100, 'other account');
INSERT INTO transactions VALUES (NULL, 1, '2016-06-30', 200, 'last in june');
INSERT INTO transactions VALUES (NULL, 1, '2016-07-01', 300, 'first in july');
INSERT INTO transactions VALUES (NULL, 1, '2016-07-02', 400, 'one more in july');
DROP TABLE IF EXISTS balances;
CREATE TABLE balances (account TINYINT, balance INT, title TINYBLOB);
INSERT INTO balances VALUES(1, 100000, 'Wells Fargo');
INSERT INTO balances VALUES(2, 50000, 'HSA');
INSERT INTO balances VALUES(3, 100000, 'First National Bank');
SELECT date,cents,title FROM transactions WHERE account=1 ORDER BY date;
select date, title, cents, ( select sum(-cents) + (select balance from balances where account = 1) from transactions where date <= O.date AND account = O.account) AS subtotal from transactions O where account = 1 order by date;