Skip to content

Commit 2ad1c94

Browse files
committed
you're doing great
1 parent 3fbe282 commit 2ad1c94

File tree

22 files changed

+551
-0
lines changed

22 files changed

+551
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
CREATE DATABASE music;
2+
3+
\c music
4+
5+
CREATE TABLE musicians (mid INT PRIMARY KEY NOT NULL, mname TEXT NOT NULL);
6+
7+
INSERT INTO musicians VALUES (1, 'Dave Mustang'), (2, 'Steven Tyler'), (3, 'Sam Smith'), (4, 'Sarah McLachlan'), (5, 'Bono'), (6, 'Steve Miller'), (7, 'Bruce Springsteen');
8+
9+
CREATE TABLE bands (bid INT PRIMARY KEY NOT NULL, bname TEXT NOT NULL);
10+
11+
INSERT INTO bands VALUES (1, 'Aerosmith'), (2, 'U2'), (3, 'Ghost'), (4, 'E Street'), (5, 'Metallica'), (6, 'Megadeath');
12+
13+
CREATE TABLE bandmembers (bmid INT PRIMARY KEY NOT NULL, bid INT REFERENCES bands(bid) NOT NULL, mid INT REFERENCES musicians(mid) NOT NULL);
14+
15+
INSERT INTO bandmembers VALUES (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5), (6,5,7), (7,4,4), (8,3,3);
16+
17+
CREATE TABLE styles (sid INT PRIMARY KEY NOT NULL, sname TEXT NOT NULL);
18+
19+
INSERT INTO styles VALUES (1,'jazz'), (2,'metal'), (3,'rock'), (4,'country'), (5,'pop'), (6,'folk');
20+
21+
CREATE TABLE bandstyles (bsid INT PRIMARY KEY NOT NULL, bid INT REFERENCES bands(bid) NOT NULL, sid INT REFERENCES styles(sid) NOT NULL);
22+
23+
INSERT INTO bandstyles VALUES (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5), (6,4,4), (7,3,3);
24+
25+
------------ queries ---------------
26+
27+
28+
SELECT m.mname, b.bname, s.sname FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
29+
30+
31+
/* generate more band members */
32+
https://play.golang.org/p/uv2g4Ap21Sl
33+
34+
INSERT INTO bandmembers VALUES (9,2,3),(10,3,5),(11,2,4),(12,1,1),(13,2,1),(14,5,2),(15,3,5),(16,4,5),(17,2,1),(18,3,2),(19,1,2),(20,4,4),(21,3,3),(22,3,4),(23,1,1),(24,2,4),(25,3,2),(26,5,2),(27,3,2),(28,1,2),(29,4,1),(30,5,4),(31,4,3),(32,4,5),(33,5,4),(34,3,2),(35,5,5),(36,1,1),(37,4,4),(38,4,1),(39,2,1),(40,1,2);
35+
36+
37+
SELECT bname, sname FROM (bands AS b LEFT JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
38+
39+
SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid;
40+
41+
SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mname, b.bname;
42+
43+
SELECT m.mid, m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mid, m.mname, b.bname;
44+
45+
/* does not work*/
46+
SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid;
47+
48+
SELECT COUNT(*) AS total FROM musicians;
49+
50+
/* does not work*/
51+
SELECT COUNT(*) AS total FROM musicians GROUP BY mname;
52+
53+
SELECT mname, COUNT(*) AS total FROM musicians GROUP BY mname;
54+
55+
SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname;
56+
57+
SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10;
58+
59+
SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname;
60+
61+
SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10;
62+

000_temp/69-review-golang/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"html/template"
5+
"net/http"
6+
)
7+
8+
var tpl *template.Template
9+
10+
func init() {
11+
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
12+
}
13+
14+
func main() {
15+
16+
http.HandleFunc("/", def)
17+
http.HandleFunc("/about", abo)
18+
http.Handle("/foobar", http.NotFoundHandler())
19+
http.ListenAndServe(":8080", nil)
20+
}
21+
22+
func def(w http.ResponseWriter, r *http.Request) {
23+
tpl.ExecuteTemplate(w, "default.gohtml", nil)
24+
}
25+
26+
func abo(w http.ResponseWriter, r *http.Request) {
27+
tpl.ExecuteTemplate(w, "about.gohtml", nil)
28+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>ABOUT</title>
9+
</head>
10+
<body>
11+
12+
13+
<h1><a href="/">HOME</a></h1>
14+
<h1>ABOUT</h1>
15+
16+
</body>
17+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>HOME</title>
9+
</head>
10+
<body>
11+
12+
<h1>HOME</h1>
13+
<h1><a href="/about">ABOUT</a></h1>
14+
15+
</body>
16+
</html>

000_temp/70-sql/having.sql

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
SELECT m.mname, b.bname, s.sname FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
2+
3+
SELECT s.sname, COUNT(b.bname) AS bands FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname;
4+
5+
SELECT s.sname, COUNT(DISTINCT(b.bname)) AS bands FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname;
6+
7+
SELECT DISTINCT(b.bname) AS name FROM bands AS b;
8+
9+
SELECT DISTINCT(bname) FROM bands;
10+
11+
SELECT * FROM bands;
12+
13+
INSERT INTO bands VALUES (7, 'Madonna');
14+
INSERT INTO bands VALUES (8, 'Madonna');
15+
16+
SELECT b.bname, s.sname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
17+
18+
INSERT INTO bandstyles VALUES (8,5,2), (9,4,1), (10,3,2), (11,2,3), (12,1,4), (13,1,5), (14,1,6);
19+
20+
SELECT m.mname, b.bname, s.sname FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
21+
22+
SELECT s.sname, COUNT(b.bname) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname;
23+
24+
SELECT s.sname, COUNT(m.mname) AS musicians FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname;
25+
26+
SELECT s.sname, COUNT(DISTINCT(b.bname)) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname;
27+
28+
SELECT bname, sname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
29+
30+
SELECT sname, bname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid ORDER BY bname;
31+
32+
SELECT DISTINCT bname, sname AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid ORDER BY bname;
33+
34+
SELECT DISTINCT sname, bname AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid ORDER BY bname;
35+
36+
SELECT DISTINCT sname, COUNT(bname) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname;
37+
38+
SELECT sname, COUNT(bname) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname;
39+
40+
SELECT DISTINCT sname, bname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
41+
42+
SELECT sname, bname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
43+
44+
SELECT sname, COUNT(bname) as bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname;
45+
46+
SELECT DISTINCT sname, COUNT(bname) as bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname;
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
/* generate more band members */
66+
https://play.golang.org/p/uv2g4Ap21Sl
67+
68+
INSERT INTO bandmembers VALUES (9,2,3),(10,3,5),(11,2,4),(12,1,1),(13,2,1),(14,5,2),(15,3,5),(16,4,5),(17,2,1),(18,3,2),(19,1,2),(20,4,4),(21,3,3),(22,3,4),(23,1,1),(24,2,4),(25,3,2),(26,5,2),(27,3,2),(28,1,2),(29,4,1),(30,5,4),(31,4,3),(32,4,5),(33,5,4),(34,3,2),(35,5,5),(36,1,1),(37,4,4),(38,4,1),(39,2,1),(40,1,2);
69+
70+
71+
SELECT bname, sname FROM (bands AS b LEFT JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid;
72+
73+
SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid;
74+
75+
SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mname, b.bname;
76+
77+
SELECT m.mid, m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mid, m.mname, b.bname;
78+
79+
/* does not work*/
80+
SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid;
81+
82+
SELECT COUNT(*) AS total FROM musicians;
83+
84+
/* does not work*/
85+
SELECT COUNT(*) AS total FROM musicians GROUP BY mname;
86+
87+
SELECT mname, COUNT(*) AS total FROM musicians GROUP BY mname;
88+
89+
SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname;
90+
91+
SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10;
92+
93+
SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname;
94+
95+
SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10;
96+

000_temp/71/assets/city.jpeg

220 KB
Loading

000_temp/71/assets/main.css

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
html, body {
2+
padding: 0;
3+
border: 0;
4+
margin: 0;
5+
box-sizing: border-box;
6+
}
7+
8+
#atf {
9+
height: 100vh;
10+
background-color: cornflowerblue;
11+
background-image: url("/stuff/city.jpeg");
12+
background-repeat: no-repeat;
13+
background-size: cover;
14+
background-position: center;
15+
display: flex;
16+
justify-content: center;
17+
align-items: center;
18+
font-size: 13vw;
19+
color: white;
20+
}
21+
22+
header {
23+
position: fixed;
24+
top: 0;
25+
left: 0;
26+
background-color: rgba(97, 115, 255, 0.44);
27+
height: 5vh;
28+
width: 100vw;
29+
display: flex;
30+
justify-content: space-between;
31+
align-items: center;
32+
}
33+
34+
header > div {
35+
font-size: 1.5rem;
36+
color: white;
37+
margin: 0 2rem;
38+
}

000_temp/71/assets/toby.jpg

5.04 KB
Loading

000_temp/71/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"html/template"
5+
"net/http"
6+
)
7+
8+
var tpl *template.Template
9+
10+
func init() {
11+
tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
12+
}
13+
14+
func main() {
15+
http.HandleFunc("/", hom)
16+
http.HandleFunc("/about", abo)
17+
http.Handle("/stuff/", http.StripPrefix("/stuff", http.FileServer(http.Dir("./assets/"))))
18+
http.ListenAndServe(":8080", nil)
19+
}
20+
21+
func hom(w http.ResponseWriter, r *http.Request) {
22+
tpl.ExecuteTemplate(w, "default.gohtml", nil)
23+
}
24+
25+
func abo(w http.ResponseWriter, r *http.Request) {
26+
tpl.ExecuteTemplate(w, "about.gohtml", nil)
27+
}

000_temp/71/templates/about.gohtml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Legal Firm ABOUT Page</title>
9+
</head>
10+
<body>
11+
12+
<h1>ABOUT</h1>
13+
14+
<a href="/home">HOME</a>
15+
<a href="/about">ABOUT</a>
16+
17+
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)