-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum_and_count.clj
45 lines (35 loc) · 1.29 KB
/
sum_and_count.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(ns seaquell.zoo.sum-and-count
(:refer-clojure
:exclude [alter distinct drop group-by into set update partition-by when])
(:require [seaquell.core :refer :all]))
;; The following queries are solutions (as of 7/21/2020) to the
;; tutorial at http://sqlzoo.net/wiki/SUM_and_COUNT
;; Each query is named for the question it answers.
;;
;; To try them out, open a repl and issue the commands below.
;; Submitting the resulting SQL into the tutorial should produce
;; correct answers.
(comment
(use 'seaquell.core)
(use 'seaquell.zoo.sum-and-count)
(select$ q1))
(def q1 (select [[:sum :population]] (from :world)))
(def q2 (select-distinct :continent (from :world)))
(def q3
(select [[:sum :gdp]] (from :world) (where {:continent "Africa"})))
(def q4
(select [[count :name]] (from :world) (where [>= :area 1000000])))
(def q5
(select [[:sum :population]]
(from :world)
(where [:in :name [vals "Estonia" "Latvia" "Lithuania"]])))
(def q6
(select [:continent [count :name]] (from :world) (group-by :continent)))
(def q7
(select [:continent [count :name]]
(from :world)
(where [>= :population 10000000])
(group-by :continent)))
(def q8
(select :continent (from :world) (group-by :continent)
(having [>= [:sum :population] 100000000])))