Skip to content

Commit 46d4aa3

Browse files
committed
you're doing great
1 parent f9b5e64 commit 46d4aa3

File tree

6 files changed

+188
-0
lines changed

6 files changed

+188
-0
lines changed

000_temp/76 sql/sales.sql

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
CREATE DATABASE sales;
2+
3+
\l
4+
5+
\c sales
6+
7+
CREATE TABLE employees (eid INT PRIMARY KEY NOT NULL, ename TEXT NOT NULL);
8+
9+
CREATE TABLE states (stid INT PRIMARY KEY NOT NULL, stname TEXT NOT NULL);
10+
11+
CREATE TABLE cities (cid INT PRIMARY KEY NOT NULL, cname TEXT NOT NULL);
12+
13+
CREATE TABLE sales (sid INT PRIMARY KEY NOT NULL, eid INT REFERENCES employees(eid) NOT NULL, cid INT REFERENCES cities(cid) NOT NULL, stid INT REFERENCES states(stid) NOT NULL, samount INT NOT NULL);
14+
15+
INSERT INTO employees VALUES (1,'James'), (2,'Moneypenny'), (3,'Ian'), (4,'Fleming'), (5,'Bond');
16+
17+
INSERT INTO states VALUES (1,'AL'), (2,'AK'), (3,'AZ'), (4,'AR'), (5,'CA');
18+
19+
INSERT INTO cities VALUES (1,'Montgomery'), (2,'Anchorage'), (3,'Phoenix'), (4,'Little Rock'), (5,'Sacramento'), (6,'Fresno'), (7,'Benicia'), (8,'San Fran'), (9,'LA'), (10,'San Diego');
20+
21+
https://play.golang.org/p/knG5I2AAi79
22+
23+
INSERT INTO sales VALUES (1,3,2,2,1948), (2,2,10,5,1419), (3,1,6,5,557), (4,5,1,1,3612), (5,5,3,3,4829), (6,2,5,5,1546), (7,2,8,5,596), (8,4,7,5,1359), (9,3,8,5,3388), (10,1,9,5,3116), (11,4,2,2,2488), (12,5,2,2,457), (13,2,8,5,1586), (14,4,7,5,3191), (15,4,5,5,2534), (16,4,8,5,4425), (17,4,10,5,2058), (18,5,2,2,2300), (19,1,1,1,2989), (20,4,9,5,4456), (21,1,2,2,2706), (22,2,7,5,4929), (23,3,2,2,4884), (24,4,7,5,4477), (25,4,3,3,548), (26,3,5,5,2564), (27,1,7,5,3724), (28,3,4,4,3234), (29,5,2,2,3134), (30,2,4,4,2103), (31,2,9,5,2647), (32,1,8,5,1604), (33,4,3,3,2306), (34,1,9,5,1452), (35,3,6,5,3788), (36,1,1,1,386), (37,3,1,1,3199), (38,2,4,4,3683), (39,3,5,5,4368), (40,2,8,5,995), (41,3,7,5,4082), (42,2,10,5,1371), (43,2,4,4,4920), (44,3,2,2,2276), (45,1,6,5,1488), (46,4,10,5,2919), (47,4,5,5,1325), (48,3,8,5,1633), (49,5,7,5,641), (50,2,7,5,3177), (51,2,1,1,3945), (52,1,5,5,4284), (53,1,2,2,1703), (54,3,9,5,3332), (55,5,9,5,2923), (56,3,4,4,4309), (57,4,4,4,1267), (58,1,1,1,541), (59,3,5,5,4758), (60,2,6,5,3140), (61,4,1,1,4801), (62,1,10,5,884), (63,5,1,1,3348), (64,1,1,1,4263), (65,1,10,5,2149), (66,1,7,5,3767), (67,2,1,1,1730), (68,2,3,3,2678), (69,1,7,5,500), (70,3,3,3,393), (71,2,9,5,4204), (72,4,9,5,3857), (73,3,10,5,1258), (74,1,3,3,2282), (75,1,4,4,518), (76,1,4,4,4097), (77,3,7,5,2621), (78,3,1,1,2130), (79,1,2,2,2521), (80,5,10,5,1565), (81,2,1,1,1282), (82,2,8,5,701), (83,3,10,5,1634), (84,5,2,2,1786), (85,1,10,5,1820), (86,1,5,5,3763), (87,1,1,1,4385), (88,1,4,4,1544), (89,1,2,2,675), (90,1,10,5,1437), (91,3,9,5,1645), (92,5,6,5,1338), (93,4,5,5,1707), (94,3,9,5,2521), (95,2,3,3,1218), (96,1,2,2,3783), (97,3,10,5,230), (98,2,2,2,956), (99,4,2,2,1154), (100,5,7,5,4968);
24+
25+
SELECT e.ename, c.cname, st.stname, s.samount FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid;
26+
27+
28+
29+
SELECT e.ename, c.cname, st.stname, s.samount FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1;
30+
31+
32+
// does not work
33+
SELECT e.ename, c.cname, st.stname, s.samount FROM (((employees AS e WHERE e.eid = 1) JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid;
34+
35+
// works
36+
SELECT e.ename FROM employees AS e WHERE e.eid = 1;
37+
38+
SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname;
39+
40+
SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1 GROUP BY e.ename, c.cname, st.stname;
41+
42+
SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname ORDER BY e.ename;
43+
44+
SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1 GROUP BY e.ename, c.cname, st.stname HAVING st.stname = 'CA';
45+
46+
SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1 AND st.stname = 'CA' GROUP BY e.ename, c.cname, st.stname;
47+
48+
49+
SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname HAVING e.ename = 'James' AND st.stname = 'CA';
50+
51+
// does not work
52+
SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname HAVING e.eid = 1 AND st.stname = 'CA';
53+
54+
5.04 KB
Loading

000_temp/77-web-server/main.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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("/", foo)
16+
http.HandleFunc("/about", bar )
17+
http.HandleFunc("/contact", con)
18+
http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets"))))
19+
http.ListenAndServe(":8080", nil)
20+
}
21+
22+
func foo(w http.ResponseWriter, r *http.Request) {
23+
tpl.ExecuteTemplate(w, "index.gohtml", 42)
24+
}
25+
26+
func bar(w http.ResponseWriter, r *http.Request) {
27+
tpl.ExecuteTemplate(w, "about.gohtml", []int{1,2,3,4,5,6,7,8,9})
28+
}
29+
30+
func con(w http.ResponseWriter, r *http.Request) {
31+
32+
type person struct {
33+
First string
34+
Age int
35+
}
36+
37+
p1 := person{
38+
First: "James",
39+
Age: 32,
40+
}
41+
42+
p2 := person {
43+
First: "Jenny",
44+
Age: 27,
45+
}
46+
47+
xp := []person{p1, p2}
48+
49+
50+
tpl.ExecuteTemplate(w, "contact.gohtml", xp)
51+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
<h1>ABOUT</h1>
13+
14+
<a href="/">HOME</a>
15+
<a href="/about">ABOUT</a>
16+
<a href="/contact">CONTACT</a>
17+
18+
<br>
19+
20+
{{if .}}
21+
{{.}}
22+
{{end}}
23+
24+
</body>
25+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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>CONTACT</title>
9+
</head>
10+
<body>
11+
12+
<h1>CONTACT</h1>
13+
14+
<a href="/">HOME</a>
15+
<a href="/about">ABOUT</a>
16+
<a href="/contact">CONTACT</a>
17+
18+
<br>
19+
20+
{{if .}}
21+
{{.}}
22+
23+
{{range .}}
24+
<h2>First: {{.First}}</h2>
25+
<h2>Age: {{.Age}}</h2>
26+
{{end}}
27+
{{end}}
28+
29+
30+
<img src="/resources/toby.jpg">
31+
32+
</body>
33+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
14+
<a href="/">HOME</a>
15+
<a href="/about">ABOUT</a>
16+
<a href="/contact">CONTACT</a>
17+
18+
<br>
19+
20+
{{if .}}
21+
{{.}}
22+
{{end}}
23+
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)