diff --git a/000_temp/52-race-condition/06_chan-pre-lecture/main.go b/000_temp/52-race-condition/06_chan-pre-lecture/main.go index 193836bb..e3083e04 100644 --- a/000_temp/52-race-condition/06_chan-pre-lecture/main.go +++ b/000_temp/52-race-condition/06_chan-pre-lecture/main.go @@ -30,4 +30,4 @@ func main() { wg.Wait() close(c) fmt.Println("total count:", counter) -} \ No newline at end of file +} diff --git a/000_temp/55-website/main.go b/000_temp/55-website/main.go index 951d0842..51e61ade 100644 --- a/000_temp/55-website/main.go +++ b/000_temp/55-website/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -14,4 +14,4 @@ func init() { func main() { loadRoutes() http.ListenAndServe(":8080", nil) -} \ No newline at end of file +} diff --git a/000_temp/55-website/rAbout.go b/000_temp/55-website/rAbout.go index 19a7e6aa..12e1a845 100644 --- a/000_temp/55-website/rAbout.go +++ b/000_temp/55-website/rAbout.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "log" + "net/http" ) func about(w http.ResponseWriter, r *http.Request) { @@ -11,4 +11,3 @@ func about(w http.ResponseWriter, r *http.Request) { log.Println(err) } } - diff --git a/000_temp/55-website/rIndex.go b/000_temp/55-website/rIndex.go index d9c23ef9..fbf9401c 100644 --- a/000_temp/55-website/rIndex.go +++ b/000_temp/55-website/rIndex.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "log" + "net/http" ) func index(w http.ResponseWriter, r *http.Request) { diff --git a/000_temp/56_SVCC-17/01a/main.go b/000_temp/56_SVCC-17/01a/main.go index edbeae10..4900f12c 100644 --- a/000_temp/56_SVCC-17/01a/main.go +++ b/000_temp/56_SVCC-17/01a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { diff --git a/000_temp/56_SVCC-17/01b/main.go b/000_temp/56_SVCC-17/01b/main.go index 1493ee89..279761d5 100644 --- a/000_temp/56_SVCC-17/01b/main.go +++ b/000_temp/56_SVCC-17/01b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -12,4 +12,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "hello world") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/01c/main.go b/000_temp/56_SVCC-17/01c/main.go index 876bf60b..c48636a0 100644 --- a/000_temp/56_SVCC-17/01c/main.go +++ b/000_temp/56_SVCC-17/01c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -10,6 +10,6 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello SVCC from Paypal") } diff --git a/000_temp/56_SVCC-17/01d/main.go b/000_temp/56_SVCC-17/01d/main.go index a87bc9e8..68f251c9 100644 --- a/000_temp/56_SVCC-17/01d/main.go +++ b/000_temp/56_SVCC-17/01d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -12,4 +12,4 @@ func main() { func index(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello GDG Fresno") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/02a/main.go b/000_temp/56_SVCC-17/02a/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/02a/main.go +++ b/000_temp/56_SVCC-17/02a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/02b/main.go b/000_temp/56_SVCC-17/02b/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/02b/main.go +++ b/000_temp/56_SVCC-17/02b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/02c/main.go b/000_temp/56_SVCC-17/02c/main.go index 15895c70..3c978b33 100644 --- a/000_temp/56_SVCC-17/02c/main.go +++ b/000_temp/56_SVCC-17/02c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -16,6 +16,6 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) } diff --git a/000_temp/56_SVCC-17/02d/main.go b/000_temp/56_SVCC-17/02d/main.go index 987da27b..21ff5e92 100644 --- a/000_temp/56_SVCC-17/02d/main.go +++ b/000_temp/56_SVCC-17/02d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/03a/main.go b/000_temp/56_SVCC-17/03a/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/03a/main.go +++ b/000_temp/56_SVCC-17/03a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/03b/main.go b/000_temp/56_SVCC-17/03b/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/03b/main.go +++ b/000_temp/56_SVCC-17/03b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/03c/main.go b/000_temp/56_SVCC-17/03c/main.go index 15895c70..3c978b33 100644 --- a/000_temp/56_SVCC-17/03c/main.go +++ b/000_temp/56_SVCC-17/03c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -16,6 +16,6 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) } diff --git a/000_temp/56_SVCC-17/03d/main.go b/000_temp/56_SVCC-17/03d/main.go index 987da27b..21ff5e92 100644 --- a/000_temp/56_SVCC-17/03d/main.go +++ b/000_temp/56_SVCC-17/03d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/04a/main.go b/000_temp/56_SVCC-17/04a/main.go index 6e93561a..d24c8f45 100644 --- a/000_temp/56_SVCC-17/04a/main.go +++ b/000_temp/56_SVCC-17/04a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,4 +23,4 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", "OUR TEAM") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/04b/main.go b/000_temp/56_SVCC-17/04b/main.go index 16916c52..a6b8f5ca 100644 --- a/000_temp/56_SVCC-17/04b/main.go +++ b/000_temp/56_SVCC-17/04b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,4 +23,4 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", "THE TEAM") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/04c/main.go b/000_temp/56_SVCC-17/04c/main.go index 612070fe..dfb4b33f 100644 --- a/000_temp/56_SVCC-17/04c/main.go +++ b/000_temp/56_SVCC-17/04c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -17,11 +17,10 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", "ACME INC") } - -func about(w http.ResponseWriter, r *http.Request){ +func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", "ABOUT OUR TEAM") } diff --git a/000_temp/56_SVCC-17/04d/main.go b/000_temp/56_SVCC-17/04d/main.go index ab0fd8b8..99d15727 100644 --- a/000_temp/56_SVCC-17/04d/main.go +++ b/000_temp/56_SVCC-17/04d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,4 +23,4 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/05a/main.go b/000_temp/56_SVCC-17/05a/main.go index dfdfeaa4..1ea5b277 100644 --- a/000_temp/56_SVCC-17/05a/main.go +++ b/000_temp/56_SVCC-17/05a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,14 +23,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/05b/main.go b/000_temp/56_SVCC-17/05b/main.go index ed9351e0..4f1d2d8a 100644 --- a/000_temp/56_SVCC-17/05b/main.go +++ b/000_temp/56_SVCC-17/05b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,14 +23,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "THE TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "THE TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/05c/main.go b/000_temp/56_SVCC-17/05c/main.go index 6a04289e..f96b5c90 100644 --- a/000_temp/56_SVCC-17/05c/main.go +++ b/000_temp/56_SVCC-17/05c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -17,20 +17,19 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", "ACME INC") } - -func about(w http.ResponseWriter, r *http.Request){ +func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "ABOUT OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "ABOUT OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) diff --git a/000_temp/56_SVCC-17/05d/main.go b/000_temp/56_SVCC-17/05d/main.go index f70678cf..d0b8460f 100644 --- a/000_temp/56_SVCC-17/05d/main.go +++ b/000_temp/56_SVCC-17/05d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,14 +23,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "ABOUT OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "ABOUT OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/06a/main.go b/000_temp/56_SVCC-17/06a/main.go index 7d08dc69..2c2eb857 100644 --- a/000_temp/56_SVCC-17/06a/main.go +++ b/000_temp/56_SVCC-17/06a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -24,14 +24,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/06b/main.go b/000_temp/56_SVCC-17/06b/main.go index d93fe774..029717f3 100644 --- a/000_temp/56_SVCC-17/06b/main.go +++ b/000_temp/56_SVCC-17/06b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -24,14 +24,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "THE TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "THE TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/06c/main.go b/000_temp/56_SVCC-17/06c/main.go index 0c66592a..2052430b 100644 --- a/000_temp/56_SVCC-17/06c/main.go +++ b/000_temp/56_SVCC-17/06c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,20 +18,19 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", "ACME INC") } - -func about(w http.ResponseWriter, r *http.Request){ +func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "ABOUT OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "ABOUT OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) diff --git a/000_temp/56_SVCC-17/07-concurrency/main.go b/000_temp/56_SVCC-17/07-concurrency/main.go index 17c82741..ad6b5cf4 100644 --- a/000_temp/56_SVCC-17/07-concurrency/main.go +++ b/000_temp/56_SVCC-17/07-concurrency/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { c := make(chan int) - go func(){ + go func() { c <- 42 }() fmt.Println(<-c) diff --git a/000_temp/57-form/01/main.go b/000_temp/57-form/01/main.go index 50f2a0f8..7b7e8f29 100644 --- a/000_temp/57-form/01/main.go +++ b/000_temp/57-form/01/main.go @@ -1,8 +1,8 @@ package _1 import ( - "net/http" "io" + "net/http" ) func main() { diff --git a/000_temp/57-form/02/main.go b/000_temp/57-form/02/main.go index 726954e7..68b3556c 100644 --- a/000_temp/57-form/02/main.go +++ b/000_temp/57-form/02/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -34,13 +34,13 @@ func processor(w http.ResponseWriter, r *http.Request) { skate := r.FormValue("skate") radio := r.FormValue("cow") - d := struct{ + d := struct { First, Last, Surf, Snow, Skate, Radio string }{ First: fname, - Last: lname, - Surf: surf, - Snow: snow, + Last: lname, + Surf: surf, + Snow: snow, Skate: skate, Radio: radio, } diff --git a/000_temp/59-html-form/main.go b/000_temp/59-html-form/main.go index 84db73fe..992111d9 100644 --- a/000_temp/59-html-form/main.go +++ b/000_temp/59-html-form/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) type GData struct { @@ -58,18 +58,17 @@ func process(w http.ResponseWriter, r *http.Request) { fn := r.FormValue("first") ln := r.FormValue("last") - d := struct{ + d := struct { GData First string - Last string + Last string }{ GData: GData{ Title: "PROCESS", }, First: fn, - Last: ln, + Last: ln, } tpl.ExecuteTemplate(w, "process.gohtml", d) } - diff --git a/000_temp/60-redirect/main.go b/000_temp/60-redirect/main.go index 9cfe5c71..57fad399 100644 --- a/000_temp/60-redirect/main.go +++ b/000_temp/60-redirect/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -11,12 +11,11 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/new", http.StatusSeeOther) io.WriteString(w, "You are at index") } -func newplace(w http.ResponseWriter, r *http.Request){ +func newplace(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "You are at newplace") } - diff --git a/000_temp/61-assertion/main.go b/000_temp/61-assertion/main.go index 3b3f5ca8..9fd92895 100644 --- a/000_temp/61-assertion/main.go +++ b/000_temp/61-assertion/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { var s interface{} - s = struct{ + s = struct { name string }{ name: "james bond", diff --git a/000_temp/62-kelowna/00-prep/01/main.go b/000_temp/62-kelowna/00-prep/01/main.go index 63baf905..f98e0ff9 100644 --- a/000_temp/62-kelowna/00-prep/01/main.go +++ b/000_temp/62-kelowna/00-prep/01/main.go @@ -4,7 +4,7 @@ import "fmt" type person struct { first string - last string + last string } type secretAgent struct { @@ -28,22 +28,20 @@ func foo(h human) { h.speak() } - func bar(h human) { h.speak() } - func main() { x := person{ first: "miss", last: "money", } - y := secretAgent { + y := secretAgent{ person: person{ first: "james", - last: "bond", + last: "bond", }, ltk: true, } diff --git a/000_temp/62-kelowna/00-prep/02/main.go b/000_temp/62-kelowna/00-prep/02/main.go index 7cd760aa..96ff7e59 100644 --- a/000_temp/62-kelowna/00-prep/02/main.go +++ b/000_temp/62-kelowna/00-prep/02/main.go @@ -3,15 +3,15 @@ package main import "fmt" func main() { - xi := []int{4,5,6,7} + xi := []int{4, 5, 6, 7} for n, i := range xi { fmt.Println(n, i) } - m := map[string]int { + m := map[string]int{ "mcleod": 47, - "bond": 27, + "bond": 27, } for k, v := range m { diff --git a/000_temp/62-kelowna/01-present/02/main.go b/000_temp/62-kelowna/01-present/02/main.go index 7cd760aa..96ff7e59 100644 --- a/000_temp/62-kelowna/01-present/02/main.go +++ b/000_temp/62-kelowna/01-present/02/main.go @@ -3,15 +3,15 @@ package main import "fmt" func main() { - xi := []int{4,5,6,7} + xi := []int{4, 5, 6, 7} for n, i := range xi { fmt.Println(n, i) } - m := map[string]int { + m := map[string]int{ "mcleod": 47, - "bond": 27, + "bond": 27, } for k, v := range m { diff --git a/000_temp/62-kelowna/01-present/03/main.go b/000_temp/62-kelowna/01-present/03/main.go index 592cdd91..39635b81 100644 --- a/000_temp/62-kelowna/01-present/03/main.go +++ b/000_temp/62-kelowna/01-present/03/main.go @@ -4,7 +4,6 @@ import "fmt" // https://play.golang.org/p/gLdpEzVm54U - type person struct { first string last string @@ -57,4 +56,4 @@ func main() { foo(p1) foo(p2) -} \ No newline at end of file +} diff --git a/000_temp/62-kelowna/02/temp.txt b/000_temp/62-kelowna/02/temp.txt new file mode 100644 index 00000000..20c8f38e --- /dev/null +++ b/000_temp/62-kelowna/02/temp.txt @@ -0,0 +1,55 @@ +INSERT INTO customers VALUES (12, 'Jamesx', 8000, 'CA'), (13, 'Jennyx', 11000, 'WA'), (14, 'Toddx', 9950, 'OR'), (15, 'Rickx', 10500, 'WA'), (16, 'Stevex', 10250, 'CA'), (17, 'Andrewx', 7750, 'OR'), (18, 'Josephinex', 13000, 'WA'), (19, 'Maxx', 12000, 'CA'), (20, 'Stephaniex', 8000, 'OR'), (21, 'Agnesx', 9999, 'WA'); + + + +INSERT INTO ingredients VALUES (1, 'Kale', '1 cup, pulled from stem'), (2, 'blueberries', 'a handful'), (3, 'pineapple', 'a handful'), (4, 'ice', 'a handful'), (5, 'juice', '1 cup'), (6, 'water', 'as much as needed'), (7, 'peanut butter', '3/4 cup'), (8, 'old-fashioned rolled oats', '1.5 cups'), (9, 'all-purpose flour', '2 cups'), (10, 'baking powder', '1 teaspoon'), (11, 'baking soda', '1 teaspon'), (12, 'salt', '1 teaspoon'), (13, 'butter', '2 sticks, softended'), (14, 'granulated sugar', '1 cup'), (15, 'brown sugar', '1 cup firmly packed'), (16, 'vanilla extract', '1 tablespoon'), (17, 'eggs', '2 large'), (18, 'semisweet chocolate chips', '12 ounces'), (19, 'semisweet chocolate, grated', '8 ounces'); + +INSERT INTO recipeingredients VALUES (1, 2, 1), (2, 2, 2), (3, 2, 3), (4, 2, 4), (5, 2, 5), (6, 2, 6), (7, 1, 7), (8,1,8), (9,1,9), (10,1,10), (11,1,11), (12,1,12), (13,1,13), (14,1,14), (15,1,15), (16,1,16), (17,1,17), (18,1,18), (19,1,19); + +SELECT rname, iname, iamount FROM recipes JOIN recipeingredients ON recipes.rid = recipeingredients.rid JOIN ingredients ON recipeingredients.iid = ingredients.iid; + + +CREATE DATABASE climbing; + +\c climbing + +CREATE TABLE categories (catID INT PRIMARY KEY NOT NULL, catName TEXT NOT NULL); + +INSERT INTO categories VALUES (1, 'easy'), (2, 'medium'), (3, 'hard'), (4, 'impossible'); + +CREATE TABLE climbs (cID INT PRIMARY KEY NOT NULL, cName TEXT NOT NULL, catID INT REFERENCES categories(catID)); + +INSERT INTO climbs VALUES (1, 'metal mark', 1), (2, 'tollhouse slab', 1), (3, 'pinnacles', 2), (4, 'Arroyo', 3), (5, 'El Cap', 3), (6, 'North Face', 4); + +SELECT cname, catname FROM climbs INNER JOIN categories ON climbs.catid = categories.catid; + + +SELECT c.cname, m.mname FROM customers AS c JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON m.mid =r.mid; + + +CREATE TABLE actors(aid INT PRIMARY KEY NOT NULL, aname TEXT NOT NULL); + +INSERT INTO actors VALUES (1, 'James'), (2, 'Jenny'), (3, 'Rock'), (4, 'Rick'), (5, 'Steve'), (6, 'Andrew'); + +CREATE TABLE moviecast (caid INT PRIMARY KEY NOT NULL, mid INT REFERENCES movies(MID), aid INT REFERENCES actors(AID)); + +INSERT INTO moviecast VALUES (1, 2, 1), (2, 2, 2), (3, 2, 3), (4, 2, 4), (5, 2, 5), (6, 2, 6), (7, 1, 3), (8,1,2), (9,1,1), (10,1,5), (11,2,5), (12,2,6), (13,3,1), (14,3,4), (15,4,5), (16,4,2), (17,5,1), (18,6,3), (19,6,4); + + +SELECT cname, rid, mname, aname FROM customers AS c JOIN rentals as r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid JOIN moviecast AS mc ON m.mid = mc.mid JOIN actors AS a ON mc.aid = a.aid; + +CREATE TABLE cphone (cpID INT PRIMARY KEY NOT NULL, cID INT REFERENCES customers(CID), cpPHONE TEXT NOT NULL); + +INSERT INTO cphone VALUES (1, 1, '007-0077'), (2, 2, '008-0088'), (3, 3, '009-0099'), (4, 4, '001,0011'), (5, 5, '002-0022'), (6, 6, '003-0033'), (7, 1, '777-8888'), (8, 2, '888-7777'), (9, 2, '999-3231'); + +CREATE TABLE aphone (apID INT PRIMARY KEY NOT NULL, aID INT REFERENCES actors(AID), apPHONE TEXT NOT NULL); + +INSERT INTO aphone VALUES (1, 1, '997-9977'), (2, 2, '998-9988'), (3, 3, '999-9999'), (4, 4, '991,9911'), (5, 5, '992-9922'), (6, 6, '993-9933'), (7, 1, '888-8888'), (8, 2, '888-8887'), (9, 2, '444-3231'); + +SELECT cname, cpphone FROM cphone AS cp JOIN customers AS c ON cp.cid = c.cid; + +SELECT aname, apphone FROM actors AS a JOIN aphone AS ap ON a.aid = ap.aid; + +SELECT cname, cpphone, aname, apphone FROM cphone AS cp JOIN customers AS c ON cp.cid = c.cid JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid JOIN moviecast AS mc ON m.mid = mc.mid JOIN actors AS a ON mc.aid = a.aid JOIN aphone AS ap ON a.aid = ap.aid; + +SELECT cname, cpphone, rid, mname, aname, apphone FROM cphone AS cp JOIN customers AS c ON cp.cid = c.cid JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid JOIN moviecast AS mc ON m.mid = mc.mid JOIN actors AS a ON mc.aid = a.aid JOIN aphone AS ap ON a.aid = ap.aid; \ No newline at end of file diff --git a/000_temp/62-kelowna/03/sql b/000_temp/62-kelowna/03/sql new file mode 100644 index 00000000..efde806d --- /dev/null +++ b/000_temp/62-kelowna/03/sql @@ -0,0 +1,80 @@ +INSERT INTO recipeclasses VALUES (1, 'italian'), (2,'french'), (3,'indian'), (4,'mexican'), (5,'thai'), (6,'chinese'), (7,'swiss'), (8,'german'), (9,'american'), (10,'japanese'), (11,'hungarian'), (12,'english'); + +INSERT INTO recipes VALUES (1,'hamburger',9,'bbq','include pickles'), (2,'bratwurst',8,'grill','drink beer while eating'), (3,'chow meain',6,'wok it','not so good as leftovers'), (4,'canoli',1,'lots of cream','wonderful dessert'), (5,'chai',3,'milk and spices baby','delicious to drink'), (6,'red wine',2,'enjoy za life','not so much for me'), (7,'burrito',4,'beans please','add hot sauce'), (8,'pad thai',5,'no fish sauce','put a fried egg on top'), (9,'swiss cheese',7,'put in the holes','melt it on crackers'), (10,'sushi',10,'do not cook the fish','add miso soup on the side'); + +SELECT recipeclassdescription, recipetitle FROM recipeclasses LEFT OUTER JOIN recipes ON recipeclasses.recipeclassid = recipes.recipeclassid; + +SELECT recipeclassdescription, recipetitle FROM recipeclasses LEFT JOIN recipes ON recipeclasses.recipeclassid = recipes.recipeclassid; + +SELECT rc.recipeclassdescription, r.recipetitle FROM recipeclasses AS rc LEFT JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid; + +SELECT rc.recipeclassdescription FROM recipeclasses AS rc LEFT JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid WHERE r.recipeid IS NULL; + +SELECT f.recipeclassdescription, r.recipetitle FROM (SELECT recipeclassid, recipeclassdescription FROM recipeclasses AS rc where rc.recipeclassdescription = 'german' OR rc.recipeclassdescription = 'italian' OR rc.recipeclassdescription = 'french') AS f LEFT JOIN recipes AS r ON f.recipeclassid = r.recipeclassid; + +SELECT f.recipetitle, rc.recipeclassdescription FROM (SELECT recipetitle, recipeclassid FROM recipes WHERE recipetitle LIKE '%a%') AS f RIGHT JOIN recipeclasses AS rc ON f.recipeclassid = rc.recipeclassid; + + + +CREATE DATABASE humanity; + +\c humanity + +CREATE TABLE humans (hid INT PRIMARY KEY NOT NULL, hname TEXT, hage INT); + +INSERT INTO humans VALUES (1,'',18), (2,'',22), (3,'jenny',27), (4,'james',32), (5,'ian',36), (6,'stephen',42), (7,'stephanie',47), (8,'agnes',49), (9,'portia',50), (10,'fidel',55), (11,'rich',62), (12,'al',78); + +SELECT f.hname FROM (SELECT hname FROM humans WHERE hname LIKE '%a%') AS f; + +SELECT f.hname, f.hage FROM (SELECT hname, hage FROM humans WHERE hage > 40) AS f; + + +SELECT f1.recipeclassdescription, f2.recipetitle FROM (SELECT recipeclasses.recipeclassid, recipeclassdescription FROM recipeclasses WHERE recipeclassdescription = 'german' OR recipeclassdescription = 'italian' OR recipeclassdescription = 'french' OR recipeclassdescription = 'hungarian') AS f1 LEFT JOIN (SELECT recipes.recipeclassid, recipetitle FROM recipes WHERE recipetitle LIKE '%o%') AS f2 on f1.recipeclassid = f2.recipeclassid; + +CREATE TABLE ingredients (ingredientid INT PRIMARY KEY NOT NULL, ingredientname TEXT); + +CREATE TABLE measurements (measurementsid INT PRIMARY KEY NOT NULL, measurementdescription TEXT); + +CREATE TABLE recipeingredients (riid INT PRIMARY KEY NOT NULL, recipeid INT NOT NULL REFERENCES recipes(recipeid), recipeseqno INT, ingredientid INT NOT NULL REFERENCES ingredients(ingredientid), measurementsid INT NOT NULL REFERENCES measurements(measurementsid)); + +INSERT INTO ingredients VALUES (1,'chocolate'), (2,'chipotle'), (3,'chicken'), (4,'beef'), (5,'flower'), (6,'butter'), (7,'milk'), (8,'broth'), (9,'salt'), (10,'baking soda'); + +INSERT INTO measurements VALUES (1,'some'), (2,'a little'), (3,'a lot'), (4,'a pinch'), (5,'until it tastes good'), (6,'not too much'), (7,'not too little'), (8,'just a pinch'), (9,'a smidge'), (10,'a generous scoop'), (11,'more than you think'), (12,'less than youd imagine'); + +INSERT INTO recipeingredients VALUES (1,6,1,7,10),(2,3,2,5,5),(3,8,3,9,7),(4,7,4,6,1),(5,4,5,3,2),(6,9,6,1,6),(7,3,7,6,9),(8,1,8,6,11),(9,1,9,8,6),(10,2,10,7,10),(11,5,11,7,6),(12,6,12,4,1),(13,7,13,8,2),(14,1,14,8,7),(15,2,15,1,3),(16,1,16,8,1),(17,2,17,4,5),(18,8,18,1,6),(19,5,19,8,3),(20,4,20,8,2),(21,9,21,7,6),(22,4,22,2,1),(23,9,23,9,1),(24,3,24,2,3),(25,9,25,6,2),(26,1,26,2,10),(27,8,27,9,6),(28,1,28,8,5),(29,3,29,8,5),(30,6,30,9,10),(31,3,31,5,10),(32,2,32,1,11),(33,4,33,1,9),(34,3,34,4,4),(35,4,35,9,8),(36,3,36,2,5),(37,4,37,2,10),(38,2,38,5,4),(39,1,39,5,6),(40,5,40,4,10),(41,3,41,2,8),(42,4,42,5,9),(43,6,43,5,2),(44,1,44,1,3),(45,8,45,9,11),(46,8,46,9,5),(47,1,47,7,3),(48,9,48,5,2),(49,9,49,6,5),(50,3,50,9,8),(51,5,51,8,5),(52,2,52,3,2),(53,4,53,4,8),(54,3,54,5,4),(55,5,55,7,1),(56,1,56,7,3),(57,7,57,8,3),(58,1,58,9,10),(59,9,59,5,11),(60,1,60,4,3),(61,2,61,1,7),(62,4,62,6,10),(63,4,63,4,9),(64,8,64,6,6),(65,6,65,7,6),(66,2,66,9,11),(67,6,67,3,11),(68,4,68,6,6),(69,6,69,3,6),(70,1,70,8,3),(71,2,71,7,4),(72,4,72,2,8),(73,8,73,3,5),(74,4,74,4,7),(75,6,75,8,9),(76,7,76,2,1),(77,8,77,3,2),(78,6,78,8,9),(79,3,79,5,10),(80,3,80,4,9),(81,7,81,7,4),(82,6,82,7,6),(83,3,83,2,10),(84,7,84,2,7),(85,9,85,2,10),(86,3,86,1,5),(87,8,87,4,2),(88,5,88,3,5),(89,6,89,4,9),(90,5,90,6,4),(91,9,91,2,9),(92,7,92,4,1),(93,7,93,4,2),(94,6,94,4,8),(95,4,95,2,5),(96,2,96,3,8),(97,5,97,3,9),(98,4,98,9,2),(99,7,99,5,2),(100,4,100,7,10); + + +SELECT recipetitle, recipeclassdescription, recipeseqno, ingredientname, measurementdescription FROM recipes AS r INNER JOIN recipeclasses AS rc ON r.recipeclassid = rc.recipeclassid INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid ORDER BY r.recipeid, ri.recipeseqno; + +INSERT INTO recipeclasses VALUES (13, 'cambodian'), (14, 'nepalese'), (15, 'tazmanian'); + +SELECT recipeclassdescription, recipetitle FROM (recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid); + + +--- does not work --- +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM (((recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid) INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid; + +--- does work --- +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM recipes AS r INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid RIGHT JOIN recipeclasses AS rc ON r.recipeclassid = rc.recipeclassid; + +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM recipes AS r INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid RIGHT JOIN recipeclasses AS rc ON r.recipeclassid = rc.recipeclassid ORDER BY r.recipeid, ri.recipeseqno; + +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM (((recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid) LEFT JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) LEFT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid; + +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM (((recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid) LEFT JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) LEFT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid ORDER BY r.recipeid, ri.recipeseqno; + + +INSERT INTO recipes VALUES (11, 'reuben sandwich', NULL ,'put pastrami on rye and grill', 'butter your bread'), (12, 'thai chicken soup', NULL, 'use lemongrass', 'so delicious'); + + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) JOIN measurements AS m ON ri.measurementsid = m.measurementsid) ORDER BY r.recipetitle, ri.recipeseqno; + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc LEFT JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) LEFT JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) LEFT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) RIGHT JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) RIGHT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) RIGHT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) FULL JOIN measurements AS m ON ri.measurementsid = m.measurementsid); \ No newline at end of file diff --git a/000_temp/62-kelowna/04-sql-union/union.sql b/000_temp/62-kelowna/04-sql-union/union.sql new file mode 100644 index 00000000..c58cf47e --- /dev/null +++ b/000_temp/62-kelowna/04-sql-union/union.sql @@ -0,0 +1,31 @@ +CREATE DATABASE exampleunion; + +\c exampleunion + +CREATE TABLE customers (cid INT PRIMARY KEY NOT NULL, first TEXT); + +INSERT INTO customers VALUES (1, 'James'), (2, 'Sergey'), (3, 'Vladimir'), (4, 'Putin'), (5, 'Coup'); + +CREATE TABLE vendors (vid INT PRIMARY KEY NOT NULL, first TEXT); + +INSERT INTO vendors VALUES (1, 'Stacey'), (2, 'Shelley'), (3, 'Sherry'), (4, 'Suzy'), (5, 'Sandy'); + +CREATE TABLE employees (eid INT PRIMARY KEY NOT NULL, first TEXT); + +INSERT INTO employees VALUES (1, 'Jeff'), (2, 'John'), (3, 'Jerry'), (4, 'Jose'), (5, 'Juan'); + +SELECT v.first FROM vendors AS v UNION SELECT e.first FROM employees AS e; + +SELECT 'customer' AS category, c.first FROM customers AS c UNION SELECT 'employee' AS category, e.first FROM employees AS e UNION SELECT 'vendor' AS category, v.first FROM vendors AS v UNION SELECT 'stuffedanimal' AS category, sa.saAnimalName FROM stuffedanimals AS sa; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c ORDER BY rowid; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c ORDER BY first; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c ORDER BY rowid, first; + +SELECT 'vendor' AS rowid, v.first AS name FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first AS name FROM employees AS e UNION SELECT 'customer' AS rowid, c.first AS name FROM customers AS c ORDER BY rowid, name; \ No newline at end of file diff --git a/000_temp/62-kelowna/05-subqueries/subqueries.sql b/000_temp/62-kelowna/05-subqueries/subqueries.sql new file mode 100644 index 00000000..fda030de --- /dev/null +++ b/000_temp/62-kelowna/05-subqueries/subqueries.sql @@ -0,0 +1,79 @@ +CREATE DATABASE acmesales; + +\c acmesales + +CREATE TABLE customers (cid INT PRIMARY KEY NOT NULL, cfirst TEXT); + +INSERT INTO customers VALUES (1,'Cory'), (2,'Casey'), (3,'Canard'), (4,'Cully'), (5,'Coffer'), (6,'Homey'); + +CREATE TABLE items (iid INT PRIMARY KEY NOT NULL, iitem TEXT); + +INSERT INTO items VALUES (1,'dog food'), (2,'tiramisu'), (3,'vino'), (4,'cheese'), (5,'chocolate'), (6,'gummy worms'), (7,'mango'); + +CREATE TABLE orders (oid INT PRIMARY KEY NOT NULL, cid INT REFERENCES customers(cid), odate TEXT); + +INSERT INTO orders VALUES (1,2,'tuesday'), (2,5,'wednesday'), (3,1,'thursday'), (4,3,'sunday'), (5,4,'saturday'), (6,5,'friday'); + +CREATE TABLE orderitems (oiid INT PRIMARY KEY NOT NULL, oid INT REFERENCES orders(oid), iid INT REFERENCES items(iid)); + +INSERT INTO orderitems VALUES (1,4,6), (2,4,5), (3,5,4), (4,6,3), (5,1,2), (6,2,1), (7,3,6), (8,4,5), (9,5,4), (10,6,3); + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid; + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c FULL JOIN orders AS o ON c.cid = o.cid FULL JOIN orderitems AS oi ON o.oid = oi.oid FULL JOIN items AS i ON oi.iid = i.iid; + +// SCALAR +// an expression that evaluates to one value +// aka, one column & one row = one field value + +SELECT o.oid, o.odate, (SELECT c.cfirst FROM customers AS c WHERE c.cid = o.cid) FROM orders AS o; + +// could have also done the above this way + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid; + +// aggregate function COUNT + +SELECT COUNT(cfirst) AS ourcustomers FROM customers; + +SELECT c.cfirst, (SELECT COUNT(*) FROM orders AS o WHERE c.cid = o.cid) AS ordercount FROM customers AS c; + +// aggregate function MAX + +SELECT MAX(cid) AS highestcid FROM customers; + +SELECT MAX(odate) AS maxday FROM orders; + +SELECT c.cfirst, (SELECT MAX(o.oid) FROM orders AS o WHERE c.cid = o.cid) AS maxoid FROM customers AS c; + +// subquery as filters +// subquery with the WHERE clause +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = (SELECT MAX(odate) FROM orders); + +// subquery as filters +// subquery with the IN keyword +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate IN (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +// ALL, SOME, ANY keywords +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = ANY (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = SOME (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = ALL (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = ALL (SELECT odate FROM orders WHERE odate LIKE 'thur%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate > ALL (SELECT odate FROM orders WHERE odate LIKE 'thur%'); + +// EXISTS +// I DO NOT KNOW HOW THIS WORKS +// MORE RESEARCH AND EXPERIMENTATION ARE NEEDED +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid; + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid WHERE i.iitem = 'chocolate'; + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid WHERE EXISTS (SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid WHERE i.iitem = 'chocolate'); + + + + diff --git a/000_temp/62-kelowna/06-hollywood/subqueries.sql b/000_temp/62-kelowna/06-hollywood/subqueries.sql new file mode 100644 index 00000000..cd457ca0 --- /dev/null +++ b/000_temp/62-kelowna/06-hollywood/subqueries.sql @@ -0,0 +1,39 @@ +CREATE DATABASE hollywood; + +\l + +\c hollywood + +CREATE TABLE customers (cid INT PRIMARY KEY NOT NULL, cname TEXT); + +INSERT INTO customers VALUES (1,'Charlie'), (2,'Chris'), (3,'Christina'), (4,'Cassandra'), (5,'Cull'), (6,'Cabron'), (7,'Carla'), (8,'Caitland'), (9,'Colleen'), (10,'Christian'); + +CREATE TABLE movies (mid INT PRIMARY KEY NOT NULL, mname TEXT); + +INSERT INTO movies VALUES (1,'Jaws'), (2,'First Blood'), (3,'Rambo'), (4,'Terms of Endearment'), (5,'Heat'), (6,'The Lives of Others'), (7,'A Man Called Ove'), (8,'Disconnect'), (9,'Ex Machina'), (10,'Castle'); + +CREATE TABLE actors (aid INT PRIMARY KEY NOT NULL, aname TEXT); + +INSERT INTO actors VALUES (1,'Alfred'), (2,'Albert'), (3,'Angel'), (4,'Angelina'), (5,'Angie'), (6,'Agnes'), (7,'Amnia'), (8,'Allison'), (9,'Alejandro'), (10,'Aerial'); + +CREATE TABLE rentals (rid INT PRIMARY KEY NOT NULL, cid INT NOT NULL REFERENCES customers(cid), mid INT NOT NULL REFERENCES movies(mid)); + +INSERT INTO rentals VALUES (1,2,8),(2,8,10),(3,2,9),(4,6,1),(5,7,1),(6,5,2),(7,3,10),(8,9,5),(9,2,6),(10,8,7),(11,6,7),(12,9,9),(13,8,8),(14,8,9),(15,1,6),(16,2,9),(17,8,2),(18,10,7),(19,8,2),(20,6,7),(21,4,1),(22,5,4),(23,4,8),(24,9,5),(25,10,4),(26,8,2),(27,10,10),(28,1,6),(29,9,9),(30,4,6),(31,2,1),(32,6,7),(33,7,9),(34,2,3),(35,4,7),(36,4,7),(37,3,9),(38,8,5),(39,8,4),(40,7,1),(41,4,4),(42,8,4),(43,2,10),(44,4,4),(45,2,3),(46,9,7),(47,7,8),(48,1,4),(49,3,4),(50,6,9),(51,6,2),(52,6,8),(53,8,1),(54,1,6),(55,1,3),(56,9,4),(57,2,3),(58,5,8),(59,8,8),(60,2,5),(61,7,3),(62,2,10),(63,7,1),(64,4,7),(65,10,2),(66,3,6),(67,6,1),(68,8,10),(69,9,9),(70,5,4),(71,5,8),(72,3,3),(73,7,10),(74,1,7),(75,2,7),(76,1,2),(77,5,5),(78,6,4),(79,2,1),(80,3,9),(81,8,2),(82,9,5),(83,3,4),(84,3,9),(85,4,9),(86,7,1),(87,6,1),(88,5,3),(89,8,6),(90,2,10),(91,1,4),(92,1,10),(93,1,4),(94,1,5),(95,8,1),(96,6,3),(97,10,1),(98,9,7),(99,6,7),(100,1,7); + +CREATE TABLE castmembers (caid INT PRIMARY KEY NOT NULL, mid INT NOT NULL REFERENCES movies(mid), aid INT NOT NULL REFERENCES actors(aid)); + +INSERT INTO castmembers VALUES (1,2,8),(2,8,10),(3,2,9),(4,6,1),(5,7,1),(6,5,2),(7,3,10),(8,9,5),(9,2,6),(10,8,7),(11,6,7),(12,9,9),(13,8,8),(14,8,9),(15,1,6),(16,2,9),(17,8,2),(18,10,7),(19,8,2),(20,6,7),(21,4,1),(22,5,4),(23,4,8),(24,9,5),(25,10,4),(26,8,2),(27,10,10),(28,1,6),(29,9,9),(30,4,6),(31,2,1),(32,6,7),(33,7,9),(34,2,3),(35,4,7),(36,4,7),(37,3,9),(38,8,5),(39,8,4),(40,7,1),(41,4,4),(42,8,4),(43,2,10),(44,4,4),(45,2,3),(46,9,7),(47,7,8),(48,1,4),(49,3,4),(50,6,9),(51,6,2),(52,6,8),(53,8,1),(54,1,6),(55,1,3),(56,9,4),(57,2,3),(58,5,8),(59,8,8),(60,2,5),(61,7,3),(62,2,10),(63,7,1),(64,4,7),(65,10,2),(66,3,6),(67,6,1),(68,8,10),(69,9,9),(70,5,4),(71,5,8),(72,3,3),(73,7,10),(74,1,7),(75,2,7),(76,1,2),(77,5,5),(78,6,4),(79,2,1),(80,3,9),(81,8,2),(82,9,5),(83,3,4),(84,3,9),(85,4,9),(86,7,1),(87,6,1),(88,5,3),(89,8,6),(90,2,10),(91,1,4),(92,1,10),(93,1,4),(94,1,5),(95,8,1),(96,6,3),(97,10,1),(98,9,7),(99,6,7),(100,1,7); + + +SELECT c.cname, m.mname FROM customers AS c JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid; + +SELECT a.aname, m.mname FROM actors AS a JOIN castmembers AS cm ON a.aid = cm.aid JOIN movies AS m ON cm.mid = m.mid; + +INSERT INTO customers VALUES (101, 'Mike'), (102, 'Max'); + +INSERT INTO movies VALUES (101, 'Aliens'), (102, 'Ragoon'); + +INSERT INTO actors VALUES (101, 'Milfred'), (102, 'Martine'); + +SELECT c.cname, m.mname, a.aname FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid FULL JOIN movies AS m ON r.mid = m.mid FULL JOIN castmembers AS cm ON m.mid = cm.mid FULL JOIN actors AS a ON cm.aid = a.aid; + diff --git a/000_temp/62-kelowna/07-sql-aggregate-funcs/agg.sql b/000_temp/62-kelowna/07-sql-aggregate-funcs/agg.sql new file mode 100644 index 00000000..95ac5eb3 --- /dev/null +++ b/000_temp/62-kelowna/07-sql-aggregate-funcs/agg.sql @@ -0,0 +1,85 @@ +/* COUNT */ + +/* from cooking database */ + +SELECT COUNT(recipetitle) AS totalRecipes FROM recipes; + +SELECT COUNT(DISTINCT recipetitle) AS totalDistRecipes FROM recipes; + +/* from hollywood database*/ +SELECT c.cname, m.mname, a.aname FROM ((((customers AS c JOIN rentals AS r ON c.cid = r.cid) JOIN movies AS m ON r.mid = m.mid) JOIN castmembers AS cm ON m.mid = cm.mid) JOIN actors AS a ON cm.aid = a.aid); + +SELECT c.cname, m.mname, a.aname FROM ((((customers AS c LEFT JOIN rentals AS r ON c.cid = r.cid) LEFT JOIN movies AS m ON r.mid = m.mid) LEFT JOIN castmembers AS cm ON m.mid = cm.mid) LEFT JOIN actors AS a ON cm.aid = a.aid); + +SELECT r.rid, m.mname FROM rentals AS r JOIN movies AS m ON r.mid = m.mid; + +SELECT r.rid, m.mname FROM rentals AS r RIGHT JOIN movies AS m ON r.mid = m.mid; + +SELECT cm.caid, a.aname FROM castmembers AS cm RIGHT JOIN actors AS a ON cm.aid = a.aid; + +SELECT cm.caid, a.aname FROM actors AS a LEFT JOIN castmembers AS cm ON a.aid = cm.aid; + +SELECT c.cname, m.mname, a.aname FROM ((((customers AS c FULL JOIN rentals AS r ON c.cid = r.cid) FULL JOIN movies AS m ON r.mid = m.mid) FULL JOIN castmembers AS cm ON m.mid = cm.mid) FULL JOIN actors AS a ON cm.aid = a.aid); + +SELECT COUNT(*) AS totalRentals FROM rentals; + +SELECT COUNT(cname) AS custs FROM customers; + +SELECT COUNT(DISTINCT cname) AS distinctCusts FROM customers; + + + +/* SUM */ + +DROP TABLE rentals; + +CREATE TABLE rentals (rid INT PRIMARY KEY NOT NULL, cid INT NOT NULL REFERENCES customers(cid), mid INT NOT NULL REFERENCES movies(mid), rAmount INT NOT NULL); + +https://play.golang.org/p/H7afRPh5bUd + +INSERT INTO rentals VALUES (1,2,8,5),(2,4,2,6),(3,8,1,4),(4,7,5,4),(5,11,10,6),(6,7,2,3),(7,9,7,3),(8,1,9,6),(9,10,8,5),(10,7,1,3),(11,1,9,5),(12,2,10,4),(13,2,2,3),(14,5,4,3),(15,6,4,6),(16,5,9,7),(17,6,4,5),(18,8,10,7),(19,8,6,6),(20,11,4,3),(21,5,1,3),(22,3,7,6),(23,2,3,6),(24,4,4,4),(25,6,9,5),(26,1,8,6),(27,7,1,6),(28,11,8,6),(29,11,10,6),(30,9,2,5),(31,4,7,4),(32,11,1,6),(33,4,4,3),(34,10,6,4),(35,1,8,5),(36,4,1,3),(37,7,3,6),(38,4,2,5),(39,11,8,5),(40,8,2,7),(41,4,3,4),(42,10,7,3),(43,1,7,7),(44,6,3,3),(45,10,1,5),(46,7,9,6),(47,1,4,7),(48,4,3,5),(49,7,10,3),(50,5,2,4),(51,7,2,7),(52,10,6,6),(53,4,1,5),(54,3,8,4),(55,7,5,5),(56,7,3,6),(57,8,9,4),(58,5,6,3),(59,8,3,5),(60,5,2,7),(61,3,4,3),(62,7,1,6),(63,1,5,5),(64,3,6,5),(65,10,1,6),(66,7,6,4),(67,11,7,7),(68,8,2,5),(69,5,1,7),(70,5,8,5),(71,8,2,6),(72,1,9,4),(73,5,8,5),(74,8,6,4),(75,11,6,5),(76,9,1,4),(77,11,3,3),(78,10,3,7),(79,5,1,3),(80,7,5,7),(81,10,2,4),(82,2,7,3),(83,3,8,6),(84,6,5,3),(85,1,6,7),(86,5,1,5),(87,9,1,7),(88,6,6,6),(89,7,1,7),(90,3,1,4),(91,11,3,7),(92,2,5,5),(93,4,4,4),(94,5,3,3),(95,8,2,5),(96,9,6,5),(97,10,3,7),(98,10,2,3),(99,9,4,6),(100,8,10,5); + +SELECT c.cname, m.mname, a.aname, r.rAmount FROM ((((customers AS c FULL JOIN rentals AS r ON c.cid = r.cid) FULL JOIN movies AS m ON r.mid = m.mid) FULL JOIN castmembers AS cm ON m.mid = cm.mid) FULL JOIN actors AS a ON cm.aid = a.aid); + +SELECT SUM(rAmount) AS totalRev FROM rentals; + +select c.cname, r.ramount from customers AS c JOIN rentals AS r ON c.cid = r.cid; + +select c.cname, r.rid, r.ramount from customers AS c JOIN rentals AS r ON c.cid = r.cid; + +select c.cname, r.rid, r.ramount from customers AS c FULL JOIN rentals AS r ON c.cid = r.cid; + +SELECT c.cid, c.cname, r.rid, r.ramount FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid; + +SELECT c.cid, c.cname, r.rid, r.ramount, m.mname, a.aname FROM ((((customers AS c FULL JOIN rentals AS r ON c.cid = r.cid) FULL JOIN movies AS m ON r.mid = m.mid) FULL JOIN castmembers AS cm ON m.mid = cm.mid) FULL JOIN actors AS a ON cm.aid = a.aid); + +SELECT c.cid, c.cname, SUM(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + +SELECT c.cid, c.cname, SUM(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid ORDER BY bigSpend DESC; + + + +/* AVG */ + +SELECT AVG(ramount) FROM rentals; + +SELECT c.cid, c.cname, AVG(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + + + +/* MAX */ +SELECT MAX(ramount) FROM rentals; + +SELECT c.cid, c.cname, MAX(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + + + +/* MIN */ +SELECT MIN(ramount) FROM rentals; + +SELECT c.cid, c.cname, MIN(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + + +/* AFTER CLASS */ + +SELECT cu.cname AS firstName FROM customers AS cu; \ No newline at end of file diff --git a/000_temp/62-kelowna/08-sql-group/agg.sql b/000_temp/62-kelowna/08-sql-group/agg.sql new file mode 100644 index 00000000..86c51d35 --- /dev/null +++ b/000_temp/62-kelowna/08-sql-group/agg.sql @@ -0,0 +1,86 @@ +CREATE DATABASE entertainers; + +\l + +\c entertainers + +CREATE TABLE entertainers (eid INT PRIMARY KEY NOT NULL, ename TEXT NOT NULL); + +\d + +\d entertainers + +CREATE TABLE engagements (enID INT PRIMARY KEY NOT NULL, eid INT NOT NULL REFERENCES entertainers(eid), encontractprice INT NOT NULL); + +INSERT INTO entertainers VALUES (1, 'WOOKIE-WOOKIE'), (2, 'HodgePodge'), (3, 'ScarlettLetters'), (4, 'TomorrowsSun'), (5, 'WhereWithAll'), (6, 'CowboyFutures'), (7, 'DesperateTortillas'), (8, 'CaldenarFlippers'), (9, 'LaughingJackals'), (10, 'CareeningForthright'); + + +generate values +https://play.golang.org/p/iET0hmFrcgf + +INSERT INTO engagements VALUES (1,2,9888),(2,8,6060),(3,2,3319),(4,6,4541),(5,7,5301),(6,5,10512),(7,3,7090),(8,9,5275),(9,2,3446),(10,8,11107),(11,6,7467),(12,9,8259),(13,8,11948),(14,8,4889),(15,1,5016),(16,2,2409),(17,8,8832),(18,10,7357),(19,8,2632),(20,6,7027),(21,4,5091),(22,5,2564),(23,4,6148),(24,9,6325),(25,10,3354),(26,8,5722),(27,10,4200),(28,1,10706),(29,9,6539),(30,4,11356),(31,2,10511),(32,6,2157),(33,7,11829),(34,2,9203),(35,4,7747),(36,4,6377),(37,3,11719),(38,8,7095),(39,8,9464),(40,7,8421),(41,4,2954),(42,8,5134),(43,2,2060),(44,4,10644),(45,2,4003),(46,9,11337),(47,7,11108),(48,1,8504),(49,3,11844),(50,6,3599),(51,6,3352),(52,6,11758),(53,8,10011),(54,1,7286),(55,1,5633),(56,9,10554),(57,2,10583),(58,5,3298),(59,8,8138),(60,2,7895),(61,7,7803),(62,2,4080),(63,7,3271),(64,4,5087),(65,10,10982),(66,3,9176),(67,6,7711),(68,8,5750),(69,9,4819),(70,5,9904),(71,5,6548),(72,3,3533),(73,7,9840),(74,1,7787),(75,2,10077),(76,1,9352),(77,5,2365),(78,6,11184),(79,2,2091),(80,3,4259),(81,8,5232),(82,9,10155),(83,3,3224),(84,3,6209),(85,4,3969),(86,7,5711),(87,6,2441),(88,5,5163),(89,8,6416),(90,2,5040),(91,1,11514),(92,1,3360),(93,1,2784),(94,1,4985),(95,8,10011),(96,6,6163),(97,10,9921),(98,9,8757),(99,6,10667),(100,1,11457); + +SELECT e.ename, en.encontractprice FROM entertainers AS e INNER JOIN engagements AS en ON e.eid = en.eid; + +SELECT e.ename, en.encontractprice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid; + +INSERT INTO entertainers VALUES (11, 'SomebodyNobodyLoves'); + +SELECT e.ename, en.encontractprice FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid; + +SELECT e.ename, en.encontractprice FROM entertainers AS e FULL JOIN engagements AS en ON e.eid = en.eid; + +SELECT COUNT(encontractprice) as TotalEngagements FROM engagements; +SELECT SUM(encontractprice) as TotalRevenue FROM engagements; +SELECT MAX(encontractprice) as MaxContractPrice FROM engagements; +SELECT MIN(encontractprice) as MinContractPrice FROM engagements; +SELECT AVG(encontractprice) as AvgContractPrice FROM engagements; + +SELECT e.ename, MAX(en.encontractprice) as MaxContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename; + +SELECT e.ename, MIN(en.encontractprice) as MinContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY MinContractPrice; + +SELECT e.ename, AVG(en.encontractprice) as AvgContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY AvgContractPrice; + +SELECT e.ename, SUM(en.encontractprice) as SumContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY SumContractPrice; + +SELECT e.ename, COUNT(en.encontractprice) as CountContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY CountContractPrice; + +SELECT e.ename, COUNT(en.encontractprice) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY NumContracts; + +SELECT e.ename, COUNT(en.encontractprice) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY NumContracts; + +SELECT e.ename, COUNT(*) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY NumContracts; + + + +/* multiple fields in group by*/ + +DROP TABLE engagements; + +DROP TABLE entertainers; + +CREATE TABLE entertainers (eid INT PRIMARY KEY NOT NULL, ename TEXT NOT NULL, ecity TEXT NOT NULL); + +INSERT INTO entertainers VALUES (1, 'WOOKIE-WOOKIE', 'Paris'), (2, 'HodgePodge', 'Paris'), (3, 'ScarlettLetters', 'Paris'), (4, 'TomorrowsSun', 'Hollywood'), (5, 'WhereWithAll', 'Hollywood'), (6, 'CowboyFutures', 'Hollywood'), (7, 'DesperateTortillas', 'New York'), (8, 'CaldenarFlippers', 'New York'), (9, 'LaughingJackals', 'San Francisco'), (10, 'CareeningForthright', 'San Francisco'); + +CREATE TABLE engagements (enID INT PRIMARY KEY NOT NULL, eid INT NOT NULL REFERENCES entertainers(eid), encontractprice INT NOT NULL); + +generate values +https://play.golang.org/p/iET0hmFrcgf + +INSERT INTO engagements VALUES (1,2,9888),(2,8,6060),(3,2,3319),(4,6,4541),(5,7,5301),(6,5,10512),(7,3,7090),(8,9,5275),(9,2,3446),(10,8,11107),(11,6,7467),(12,9,8259),(13,8,11948),(14,8,4889),(15,1,5016),(16,2,2409),(17,8,8832),(18,10,7357),(19,8,2632),(20,6,7027),(21,4,5091),(22,5,2564),(23,4,6148),(24,9,6325),(25,10,3354),(26,8,5722),(27,10,4200),(28,1,10706),(29,9,6539),(30,4,11356),(31,2,10511),(32,6,2157),(33,7,11829),(34,2,9203),(35,4,7747),(36,4,6377),(37,3,11719),(38,8,7095),(39,8,9464),(40,7,8421),(41,4,2954),(42,8,5134),(43,2,2060),(44,4,10644),(45,2,4003),(46,9,11337),(47,7,11108),(48,1,8504),(49,3,11844),(50,6,3599),(51,6,3352),(52,6,11758),(53,8,10011),(54,1,7286),(55,1,5633),(56,9,10554),(57,2,10583),(58,5,3298),(59,8,8138),(60,2,7895),(61,7,7803),(62,2,4080),(63,7,3271),(64,4,5087),(65,10,10982),(66,3,9176),(67,6,7711),(68,8,5750),(69,9,4819),(70,5,9904),(71,5,6548),(72,3,3533),(73,7,9840),(74,1,7787),(75,2,10077),(76,1,9352),(77,5,2365),(78,6,11184),(79,2,2091),(80,3,4259),(81,8,5232),(82,9,10155),(83,3,3224),(84,3,6209),(85,4,3969),(86,7,5711),(87,6,2441),(88,5,5163),(89,8,6416),(90,2,5040),(91,1,11514),(92,1,3360),(93,1,2784),(94,1,4985),(95,8,10011),(96,6,6163),(97,10,9921),(98,9,8757),(99,6,10667),(100,1,11457); + +SELECT e.ecity, e.ename, COUNT(*) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ecity, e.ename ORDER BY e.ecity, NumContracts; + +/* simulating DISTINCT */ + +SELECT ecity FROM entertainers; + +SELECT DISTINCT(ecity) FROM entertainers; + +SELECT ecity FROM entertainers GROUP BY ecity; + +SELECT ecity, COUNT(*) AS bandspercity FROM entertainers GROUP BY ecity; + + diff --git a/000_temp/63-fall-2018/016-fun-with-text/main.go b/000_temp/63-fall-2018/016-fun-with-text/main.go new file mode 100644 index 00000000..bc445452 --- /dev/null +++ b/000_temp/63-fall-2018/016-fun-with-text/main.go @@ -0,0 +1,18 @@ +package main + +import "fmt" + +func main() { + x := "ABCDE" + fmt.Println(x) + + fmt.Printf("%T\n", x) + + xr := []rune(x) + fmt.Println(xr) + + for _, v := range xr { + fmt.Printf("%d - %b - %#X\n", v, v, v) + } + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/017-slice/main.go b/000_temp/63-fall-2018/017-slice/main.go new file mode 100644 index 00000000..ea59942c --- /dev/null +++ b/000_temp/63-fall-2018/017-slice/main.go @@ -0,0 +1,25 @@ +package main + +import "fmt" + +func main() { + x := 42 + y := 43 + xi := []int{x, y} + + fmt.Printf("%T\n", x) + fmt.Printf("%T\n", y) + fmt.Printf("%T\n", xi) + + fmt.Println(xi) + + a := "James" + b := "Jenny" + xs := []string{a, b} + + fmt.Printf("%T\n", a) + fmt.Printf("%T\n", b) + fmt.Printf("%T\n", xs) + fmt.Println(xs) + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/018-map/main.go b/000_temp/63-fall-2018/018-map/main.go new file mode 100644 index 00000000..c84807fd --- /dev/null +++ b/000_temp/63-fall-2018/018-map/main.go @@ -0,0 +1,11 @@ +package main + +import "fmt" + +func main() { + m := map[string]int{"James":7, "Jenny":8,} + fmt.Printf("%T\n", m) + fmt.Println(m) + + fmt.Println(m["James"]) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/019-struct/01/main.go b/000_temp/63-fall-2018/019-struct/01/main.go new file mode 100644 index 00000000..d32ae55d --- /dev/null +++ b/000_temp/63-fall-2018/019-struct/01/main.go @@ -0,0 +1,16 @@ +package _1 + +import "fmt" + +type hotdog int +var x hotdog + +func main() { + x = 7 + fmt.Printf("%T\n", x) + fmt.Println(x) + y := int(x) + fmt.Printf("%T\n", y) + fmt.Println(y) + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/019-struct/02/main.go b/000_temp/63-fall-2018/019-struct/02/main.go new file mode 100644 index 00000000..7cb3b388 --- /dev/null +++ b/000_temp/63-fall-2018/019-struct/02/main.go @@ -0,0 +1,18 @@ +package main + +import "fmt" + +type person struct { + first string + license int + sayings []string +} + +func main() { + p1 := person{ + first: "James", + license: 007, + sayings: []string{"Shaken, not stirred", "Bond, James Bond",}, + } + fmt.Println(p1) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/019-struct/03/main.go b/000_temp/63-fall-2018/019-struct/03/main.go new file mode 100644 index 00000000..61de635f --- /dev/null +++ b/000_temp/63-fall-2018/019-struct/03/main.go @@ -0,0 +1,31 @@ +package main + +import "fmt" + +type person struct { + first string + license int + sayings []string +} + +func main() { + p1 := person{ + first: "James", + license: 7, + sayings: []string{"Shaken, not stirred", "Bond, James Bond",}, + } + fmt.Println(p1) + + p2 := person{ + first: "Jenny", + license: 8, + sayings: []string{"When Bond can't handle it, call me", "I will always love Bond",}, + } + fmt.Println(p2) + + xp := []person{p1, p2} + fmt.Println(xp) + + mp := map[string]person{"Mr":p1, "Ms":p2,} + fmt.Println(mp) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/020-looping/01/main.go b/000_temp/63-fall-2018/020-looping/01/main.go new file mode 100644 index 00000000..b73205fc --- /dev/null +++ b/000_temp/63-fall-2018/020-looping/01/main.go @@ -0,0 +1,25 @@ +package main + +import "fmt" + +func main() { + + /* + for { + fmt.Println("hello") + } + */ + + // for init; cond; incrementor {code} + for i := 0; i <= 10; i++ { + fmt.Println(i) + } + + for i := 0; ; i++ { + fmt.Println(i, i) + if i == 11 { + break + } + } + +} diff --git a/000_temp/63-fall-2018/020-looping/02/main.go b/000_temp/63-fall-2018/020-looping/02/main.go new file mode 100644 index 00000000..1fb0b8ee --- /dev/null +++ b/000_temp/63-fall-2018/020-looping/02/main.go @@ -0,0 +1,33 @@ +package main + +import "fmt" + +func main() { + xi := []int{2, 3, 4, 5, 7, 9, 42} + + for i, v := range xi { + fmt.Println(i, v) + } + + for idx := range xi { + fmt.Println(idx) + } + + for _, val := range xi { + fmt.Println("-",val) + } + + m := map[string]int{"James":32, "Jenny":27,} + + for k, v := range m { + fmt.Println(k, v) + } + + for key := range m { + fmt.Println(key) + } + + for _, value := range m { + fmt.Println("-", value) + } +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/021-receiver/01/main.go b/000_temp/63-fall-2018/021-receiver/01/main.go new file mode 100644 index 00000000..608fdde7 --- /dev/null +++ b/000_temp/63-fall-2018/021-receiver/01/main.go @@ -0,0 +1,42 @@ +package main + +import "fmt" + +type person struct { + first string + last string + saying string +} + +// func (receiver) identifier(parameters) (returns) {code} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +func main() { + p1 := person{ + first: "James", + last: "Bond", + saying: "Shaken, not stirred.", + } + + p2 := person{ + first: "Jenny", + last: "Moneypenny", + saying: "Helllllllo, James.", + } + + fmt.Println(p1) + fmt.Println(p2) + + fmt.Println("---------") + + fmt.Println(p1.first, "says", p1.saying) + fmt.Println(p2.first, "says", p2.saying) + + fmt.Println("---------") + + p1.speak() + p2.speak() +} diff --git a/000_temp/63-fall-2018/022-interfaces/01/main.go b/000_temp/63-fall-2018/022-interfaces/01/main.go new file mode 100644 index 00000000..e194fb3a --- /dev/null +++ b/000_temp/63-fall-2018/022-interfaces/01/main.go @@ -0,0 +1,71 @@ +package main + +import "fmt" + +type person struct { + first string + last string + saying string +} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +func (sa secretAgent) speak() { + fmt.Println(sa.first, "says wackabacka haha", sa.saying) +} + +type secretAgent struct { + person + ltk bool +} +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func main() { + p1 := person{ + first: "James", + last: "Bond", + saying: "Shaken, not stirred.", + } + + p2 := person{ + first: "Jenny", + last: "Moneypenny", + saying: "Helllllllo, James.", + } + + sa1 := secretAgent{ + person: person{ + first: "Ian", + last: "Fleming", + saying: "The books were based on real stories", + }, + ltk: true, + } + + fmt.Println(p1) + fmt.Println(p2) + + fmt.Println("---------") + + fmt.Println(p1.first, "says", p1.saying) + fmt.Println(p2.first, "says", p2.saying) + + fmt.Println("---------") + + p1.speak() + p2.speak() + + fmt.Println("--------- interface") + + foo(p1) + foo(p2) + foo(sa1) +} diff --git a/000_temp/63-fall-2018/022-interfaces/02/main.go b/000_temp/63-fall-2018/022-interfaces/02/main.go new file mode 100644 index 00000000..e194fb3a --- /dev/null +++ b/000_temp/63-fall-2018/022-interfaces/02/main.go @@ -0,0 +1,71 @@ +package main + +import "fmt" + +type person struct { + first string + last string + saying string +} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +func (sa secretAgent) speak() { + fmt.Println(sa.first, "says wackabacka haha", sa.saying) +} + +type secretAgent struct { + person + ltk bool +} +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func main() { + p1 := person{ + first: "James", + last: "Bond", + saying: "Shaken, not stirred.", + } + + p2 := person{ + first: "Jenny", + last: "Moneypenny", + saying: "Helllllllo, James.", + } + + sa1 := secretAgent{ + person: person{ + first: "Ian", + last: "Fleming", + saying: "The books were based on real stories", + }, + ltk: true, + } + + fmt.Println(p1) + fmt.Println(p2) + + fmt.Println("---------") + + fmt.Println(p1.first, "says", p1.saying) + fmt.Println(p2.first, "says", p2.saying) + + fmt.Println("---------") + + p1.speak() + p2.speak() + + fmt.Println("--------- interface") + + foo(p1) + foo(p2) + foo(sa1) +} diff --git a/000_temp/63-fall-2018/023-review/main.go b/000_temp/63-fall-2018/023-review/main.go new file mode 100644 index 00000000..9f33dc01 --- /dev/null +++ b/000_temp/63-fall-2018/023-review/main.go @@ -0,0 +1,124 @@ +package main + +import "fmt" + +var c int +var d = 43 + +const z = 142 + +type person struct { + first string + age int + saying string +} + +// func receiver identifier(params) returns {code} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +type secretagent struct { + person + ltk bool +} + +func (sa secretagent) speak() { + fmt.Println(sa.first, "says even more", sa.saying) +} + +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func main() { + a := "James" + fmt.Println(a) + fmt.Printf("%T\n", a) + + b := fmt.Sprint("Hello", a) + fmt.Println(b) + + c = 42 + fmt.Println("c:", c) + + d = 43 + fmt.Println("d:", d) + fmt.Printf("d type: %T\n", d) + + // slice AGGREGATE or COMPOSITE data structure + + ee := []int{2,3,4,7,9,} + fmt.Println(ee) + + // it was going SEQUENCE + // now it's going ITERATIVE + + for i, v := range ee { + fmt.Println(i, v) + // conditional logic + if i == 3 { + fmt.Println("HEY, i is EQUAL TO", i) + } + } + + + // map AGGREGATE or COMPOSITE data structure + f := map[string]int{"James":32, "Jenny":27,} + fmt.Println(f) + + for k, v := range f { + fmt.Println(k, v) + } + + // struct AGGREGATE or COMPOSITE data structure + p1 := person{ + first: "James", + age: 32, + saying: "shaken, not stirred", + } + + p2 := person { + first: "Jenny", + age: 27, + saying: "nobody does it better", + } + + xp := []person{p1, p2} + fmt.Println(xp) + for i2, v2 := range xp { + fmt.Println(i2, v2) + } + + // loop init, cond, post + for j := 0; j < 10; j++ { + fmt.Println(j) + } + + sa1 := secretagent{ + person: person{ + first: "Jack", + age: 29, + saying: "Blahb blahblabhalbhablhab", + }, + ltk: true, + } + fmt.Println(sa1) + fmt.Println(sa1.first) + fmt.Println(sa1.person.first) + + p1.speak() + p2.speak() + sa1.speak() + fmt.Println("--") + foo(p1) + foo(p2) + foo(sa1) + + fmt.Println(z) +} diff --git a/000_temp/63-fall-2018/024-unfurling-slice/main.go b/000_temp/63-fall-2018/024-unfurling-slice/main.go new file mode 100644 index 00000000..5cbce4f9 --- /dev/null +++ b/000_temp/63-fall-2018/024-unfurling-slice/main.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +func main() { + xi := []int{1,2,4,5,7,8,9,} + foo(xi...) +} + +func foo(i ...int) { + fmt.Println(i) + fmt.Printf("%T\n", i) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/025-defer/main.go b/000_temp/63-fall-2018/025-defer/main.go new file mode 100644 index 00000000..26cd71ca --- /dev/null +++ b/000_temp/63-fall-2018/025-defer/main.go @@ -0,0 +1,26 @@ +package main + +import "fmt" + +func main() { + defer foo() + bar() +} + +func foo() { + fmt.Println("foooooooo") +} + +func bar() { + fmt.Println("barrrrrrrrr") + defer one() + two() +} + +func one() { + fmt.Println("oneeeeeee") +} + +func two() { + fmt.Println("twoooooooooo") +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/026-anonymous-func/main.go b/000_temp/63-fall-2018/026-anonymous-func/main.go new file mode 100644 index 00000000..6f1cd19d --- /dev/null +++ b/000_temp/63-fall-2018/026-anonymous-func/main.go @@ -0,0 +1,15 @@ +package main + +import "fmt" + +func main() { + foo() + + // anonymous func + + func(x int){ + fmt.Println(x) + }(4) +} + +func foo() {fmt.Println("this is foo")} \ No newline at end of file diff --git a/000_temp/63-fall-2018/027-func-expression/main.go b/000_temp/63-fall-2018/027-func-expression/main.go new file mode 100644 index 00000000..f536aab4 --- /dev/null +++ b/000_temp/63-fall-2018/027-func-expression/main.go @@ -0,0 +1,27 @@ +package main + +import "fmt" + +func main() { + a := foo("something") + fmt.Println(a) + + d := 14 + b := func(z string){ + fmt.Println(z) + } + + fmt.Printf("%T\n", d) + fmt.Printf("%T\n", b) + + b("james") + b("jenny") + x := foo("cat") + y := foo("bird") + fmt.Println(x,y) + fmt.Println(d) +} + +func foo(s string) string { + return s + "dogggggggg" +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/028-returning-a-func/main.go b/000_temp/63-fall-2018/028-returning-a-func/main.go new file mode 100644 index 00000000..9fc52167 --- /dev/null +++ b/000_temp/63-fall-2018/028-returning-a-func/main.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +func main() { + x := foo() + y := foo() + fmt.Printf("%T\t %T\n", x,y) + + func(z string){ + fmt.Println(z) + }("james") + + x("jenny") + y("dogggggggggy") + +} + +func foo() func(string) { + return func(z string){ + fmt.Println(z) + } +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/029-pointers/main.go b/000_temp/63-fall-2018/029-pointers/main.go new file mode 100644 index 00000000..e53221a7 --- /dev/null +++ b/000_temp/63-fall-2018/029-pointers/main.go @@ -0,0 +1,19 @@ +package main + +import "fmt" + +func main() { + x := 42 + fmt.Println(x) + fmt.Printf("%T\n", x) + fmt.Println(&x) + + y := &x + fmt.Println(y) + fmt.Printf("%T\n", y) + fmt.Println(*y) + + *y = 43 + + fmt.Println(x) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/030-os-args/main.go b/000_temp/63-fall-2018/030-os-args/main.go new file mode 100644 index 00000000..2babcccd --- /dev/null +++ b/000_temp/63-fall-2018/030-os-args/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "os" + "fmt" +) + +func main() { + fmt.Println(os.Args[0]) + fmt.Println(os.Args[1]) + fmt.Println(os.Args[2]) + fmt.Println(os.Args[3]) +} diff --git a/000_temp/63-fall-2018/031-string-template/main.go b/000_temp/63-fall-2018/031-string-template/main.go new file mode 100644 index 00000000..7d1d6803 --- /dev/null +++ b/000_temp/63-fall-2018/031-string-template/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "os" + "log" + "strings" + "io" +) + +func main() { + // CREATE STRING + // assign to variable + name := "James" + str := `html here` + name + `more html` + fmt.Println(str) + + // CREATE STRING + // string print + s := fmt.Sprint(`mas ` + name + `menos`) + fmt.Println(s) + + // CREATE FILE + // io.Copy to the file + nf, err := os.Create("newfile.txt") + if err != nil { + log.Fatal("whoops", err) + } + + io.Copy(nf, strings.NewReader(s)) + + // CREATE FILE + // writestring to file + nf2, err := os.Create("newfile2.txt") + if err != nil { + log.Fatal("whoops", err) + } + + n, err := nf2.WriteString(str) + if err != nil { + log.Fatal("whoops2", err) + } + + fmt.Println("bytes written", n) +} diff --git a/000_temp/63-fall-2018/032-text-template/main.go b/000_temp/63-fall-2018/032-text-template/main.go new file mode 100644 index 00000000..6285de4a --- /dev/null +++ b/000_temp/63-fall-2018/032-text-template/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "text/template" + "log" + "os" + "fmt" +) + +func main() { + tpl, err := template.ParseFiles("one.txt", "two.txt") + if err != nil { + log.Fatal("whoops", err) + } + + fmt.Println("\n-----") + tpl.ExecuteTemplate(os.Stdout, "one.txt", nil) + + fmt.Println("\n\n-----") + tpl.ExecuteTemplate(os.Stdout, "two.txt", "James") + fmt.Println("\n\n") +} diff --git a/000_temp/63-fall-2018/032-text-template/one.txt b/000_temp/63-fall-2018/032-text-template/one.txt new file mode 100644 index 00000000..045061a0 --- /dev/null +++ b/000_temp/63-fall-2018/032-text-template/one.txt @@ -0,0 +1 @@ +Hello, this is file one. \ No newline at end of file diff --git a/000_temp/63-fall-2018/032-text-template/two.txt b/000_temp/63-fall-2018/032-text-template/two.txt new file mode 100644 index 00000000..c93bf5b8 --- /dev/null +++ b/000_temp/63-fall-2018/032-text-template/two.txt @@ -0,0 +1 @@ +Hello, this is file two and my name is {{.}} \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/main.go b/000_temp/63-fall-2018/033-parseglob/main.go new file mode 100644 index 00000000..0d024b14 --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "text/template" + "os" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*")) +} + +func main() { + err := tpl.ExecuteTemplate(os.Stdout, "one.gohtml", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "two.gohtml", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "lasagne.php", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "anaheim.dland", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "lets.blowitup", nil) + if err != nil { + panic(err) + } +} diff --git a/000_temp/63-fall-2018/033-parseglob/templates/anaheim.dland b/000_temp/63-fall-2018/033-parseglob/templates/anaheim.dland new file mode 100644 index 00000000..c8540638 --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/anaheim.dland @@ -0,0 +1,2 @@ +this is file anaheim +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/templates/lasagne.php b/000_temp/63-fall-2018/033-parseglob/templates/lasagne.php new file mode 100644 index 00000000..0596157e --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/lasagne.php @@ -0,0 +1,2 @@ +this is file lasagne +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/templates/one.gohtml b/000_temp/63-fall-2018/033-parseglob/templates/one.gohtml new file mode 100644 index 00000000..d7432a4c --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/one.gohtml @@ -0,0 +1,2 @@ +this is file one +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/templates/two.gohtml b/000_temp/63-fall-2018/033-parseglob/templates/two.gohtml new file mode 100644 index 00000000..d2648063 --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/two.gohtml @@ -0,0 +1,2 @@ +this is file two +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/main.go b/000_temp/63-fall-2018/034-pass-in-data-aggregate/main.go new file mode 100644 index 00000000..4138fcfa --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "text/template" + "os" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*")) +} + +type person struct { + First string + Last string + Age int +} + +func main() { + + p1 := person{ + First: "James", + Last: "Bond", + Age: 32, + } + + err := tpl.ExecuteTemplate(os.Stdout, "one.gohtml", p1) + if err != nil { + panic(err) + } + + p2 := person{ + First: "Jenny", + Last: "Moneypenny", + Age: 27, + } + + xp := []person{p1, p2} + err = tpl.ExecuteTemplate(os.Stdout, "two.gohtml", xp) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "lasagne.php", p1) + if err != nil { + panic(err) + } + +} diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/lasagne.php b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/lasagne.php new file mode 100644 index 00000000..175b0a27 --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/lasagne.php @@ -0,0 +1,2 @@ +this is file lasagne {{.First}} is {{.Last}} +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/one.gohtml b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/one.gohtml new file mode 100644 index 00000000..a7bd2240 --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/one.gohtml @@ -0,0 +1,2 @@ +this is file one {{.}} +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/two.gohtml b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/two.gohtml new file mode 100644 index 00000000..0a8c762e --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/two.gohtml @@ -0,0 +1,2 @@ +this is file two {{.}} +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/035-hash-bucket/main.go b/000_temp/63-fall-2018/035-hash-bucket/main.go new file mode 100644 index 00000000..abc30424 --- /dev/null +++ b/000_temp/63-fall-2018/035-hash-bucket/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "net/http" +) + +func main() { + // get the book moby dick + res, err := http.Get("http://www.gutenberg.org/files/2701/2701-0.txt") + if err != nil { + log.Fatal(err) + } + + defer res.Body.Close() + scanner := bufio.NewScanner(res.Body) + // scan the page + // Set the split function for the scanning operation. + scanner.Split(bufio.ScanWords) + // Create slice to hold counts + buckets := make([]int, 2000) + // Loop over the words + for scanner.Scan() { + fmt.Print(scanner.Text(), " - ") + n := hashBucket(scanner.Text()) + buckets[n]++ + } + fmt.Println(buckets[65:123]) + // fmt.Println("***************") + // for i := 28; i <= 126; i++ { + // fmt.Printf("%v - %c - %v \n", i, i, buckets[i]) + // } +} + +func hashBucket(word string) int { + fmt.Print(word[0], " ---- ") + fmt.Printf("%#U\n", word[0]) + return int(word[0]) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/036-templates-review/main.go b/000_temp/63-fall-2018/036-templates-review/main.go new file mode 100644 index 00000000..ebbb00ac --- /dev/null +++ b/000_temp/63-fall-2018/036-templates-review/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "html/template" + "os" + "log" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + err := tpl.ExecuteTemplate(os.Stdout, "main.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "about.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + f, err := os.Create("main.html") + if err != nil { + log.Fatal("another error", err) + } + defer f.Close() + + f2, err := os.Create("about.html") + if err != nil { + log.Fatal("another error", err) + } + defer f2.Close() + + err = tpl.ExecuteTemplate(f, "main.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + err = tpl.ExecuteTemplate(f2, "about.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/036-templates-review/templates/about.gohtml b/000_temp/63-fall-2018/036-templates-review/templates/about.gohtml new file mode 100644 index 00000000..89312acc --- /dev/null +++ b/000_temp/63-fall-2018/036-templates-review/templates/about.gohtml @@ -0,0 +1,12 @@ + + +
+ +
+
+
+
\ No newline at end of file
diff --git a/000_temp/72/assets/toby.jpg b/000_temp/72/assets/toby.jpg
new file mode 100644
index 00000000..16fe5330
Binary files /dev/null and b/000_temp/72/assets/toby.jpg differ
diff --git a/000_temp/72/main.go b/000_temp/72/main.go
new file mode 100644
index 00000000..b3795881
--- /dev/null
+++ b/000_temp/72/main.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "html/template"
+ "net/http"
+)
+
+var tpl *template.Template
+
+func init() {
+ tpl = template.Must(template.ParseGlob("templates/*.gohtml"))
+}
+
+func main() {
+ http.HandleFunc("/", foo)
+ http.HandleFunc("/about", bar)
+ http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets"))))
+ http.ListenAndServe(":8080", nil)
+}
+
+func foo(w http.ResponseWriter, r *http.Request) {
+ tpl.ExecuteTemplate(w, "index.gohtml", nil)
+}
+
+func bar(w http.ResponseWriter, r *http.Request) {
+ tpl.ExecuteTemplate(w, "about.gohtml", nil)
+}
diff --git a/000_temp/72/templates/about.gohtml b/000_temp/72/templates/about.gohtml
new file mode 100644
index 00000000..58bd92b0
--- /dev/null
+++ b/000_temp/72/templates/about.gohtml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/000_temp/73/01/main.go b/000_temp/73/01/main.go
new file mode 100644
index 00000000..8fd45780
--- /dev/null
+++ b/000_temp/73/01/main.go
@@ -0,0 +1,27 @@
+package main
+
+import "fmt"
+
+
+// a VALUE of TYPE
+
+var x int
+var s string
+var b bool
+var i float64
+
+func main() {
+ x = 42
+ s = "James"
+ b = true
+ i = 42.123
+ fmt.Println(x, s, b, i)
+
+ f := 43
+ g := "Bond"
+ h := false
+ j := 43.342
+ fmt.Println(f, g, h, j)
+
+ fmt.Printf("%T\t %T\t %T\t %T\t \n", f, g, h, j)
+}
\ No newline at end of file
diff --git a/000_temp/73/02/main.go b/000_temp/73/02/main.go
new file mode 100644
index 00000000..f6b872e7
--- /dev/null
+++ b/000_temp/73/02/main.go
@@ -0,0 +1,28 @@
+package main
+
+import "fmt"
+
+// AGGREGATE or COMPOSITE
+func main() {
+ xi := []int{4,5,6,7,42}
+
+ fmt.Println(xi)
+
+ for p, v := range xi {
+ fmt.Println(p, v)
+ }
+
+ // FOR declaration; condition; post {}
+ n := 42
+ for {
+ fmt.Println(n)
+ n++
+ if n == 1000 {
+ break
+ }
+ }
+
+ for i := 1000; i <= 2000; i++ {
+ fmt.Println(i)
+ }
+}
diff --git a/000_temp/73/03/main.go b/000_temp/73/03/main.go
new file mode 100644
index 00000000..8b568604
--- /dev/null
+++ b/000_temp/73/03/main.go
@@ -0,0 +1,13 @@
+package main
+
+import "fmt"
+
+type hotdog int
+
+var hd hotdog
+
+func main() {
+ hd = 42
+ fmt.Println(hd)
+ fmt.Printf("%T\n", hd)
+}
diff --git a/000_temp/73/04/main.go b/000_temp/73/04/main.go
new file mode 100644
index 00000000..6b2ef70d
--- /dev/null
+++ b/000_temp/73/04/main.go
@@ -0,0 +1,31 @@
+package main
+
+import "fmt"
+
+type person struct {
+ first string
+ age int
+}
+
+type secretAgent struct {
+ person
+ ltk bool
+}
+
+func main() {
+ p := person{
+ first: "Miss Moneypenny",
+ age: 27,
+ }
+
+ sa := secretAgent {
+ person: person {
+ first: "James",
+ age: 32,
+ },
+ ltk: true,
+ }
+
+ fmt.Println(p)
+ fmt.Println(sa)
+}
\ No newline at end of file
diff --git a/000_temp/73/05/main.go b/000_temp/73/05/main.go
new file mode 100644
index 00000000..fba21fb7
--- /dev/null
+++ b/000_temp/73/05/main.go
@@ -0,0 +1,19 @@
+package main
+
+import "fmt"
+
+func main() {
+ x := 42
+ fmt.Println("x", x)
+ fmt.Println(&x)
+
+ y := &x
+
+ fmt.Printf("%v\t %T\n", x, x)
+ fmt.Printf("%v\t %T\n", y, y)
+ fmt.Println(*y)
+
+ *y = 100
+ fmt.Println("y", *y)
+ fmt.Println("x", x)
+}
diff --git a/000_temp/73/06/main.go b/000_temp/73/06/main.go
new file mode 100644
index 00000000..fb9b32f5
--- /dev/null
+++ b/000_temp/73/06/main.go
@@ -0,0 +1,26 @@
+package main
+
+import "fmt"
+
+func main() {
+ a := 42
+ fmt.Println("a", a)
+
+ foo(a)
+ fmt.Println("a after foo", a)
+
+ bar(&a)
+ fmt.Println("a after bar", a)
+}
+
+
+func foo(b int) {
+ b = 43
+ fmt.Println("b", b)
+}
+
+func bar(c *int) {
+ *c = 44
+ fmt.Println("c", c)
+ fmt.Println("*c", *c)
+}
\ No newline at end of file
diff --git a/000_temp/74/index.html b/000_temp/74/index.html
new file mode 100644
index 00000000..bae7e1cd
--- /dev/null
+++ b/000_temp/74/index.html
@@ -0,0 +1,43 @@
+
+
+
+
+
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit. A atque autem, consectetur deleniti dolor expedita fugiat + fugit harum illum iste itaque maiores maxime non obcaecati omnis quam ratione recusandae suscipit.
+ + + +
+
+
+
\ No newline at end of file
diff --git a/000_temp/77-web-server/templates/index.gohtml b/000_temp/77-web-server/templates/index.gohtml
new file mode 100644
index 00000000..1aa33933
--- /dev/null
+++ b/000_temp/77-web-server/templates/index.gohtml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/000_temp/88-whole-enchilada/texan b/000_temp/88-whole-enchilada/texan
new file mode 100755
index 00000000..c22cc5a1
Binary files /dev/null and b/000_temp/88-whole-enchilada/texan differ
diff --git a/000_temp/90-div/index.html b/000_temp/90-div/index.html
new file mode 100644
index 00000000..f45958a8
--- /dev/null
+++ b/000_temp/90-div/index.html
@@ -0,0 +1,417 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/000_temp/92-whole-enchilada-2/templates/update.gohtml b/000_temp/92-whole-enchilada-2/templates/update.gohtml
new file mode 100644
index 00000000..3e0261fd
--- /dev/null
+++ b/000_temp/92-whole-enchilada-2/templates/update.gohtml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ {{template "polarbear"}}
+