1
+
2
+ -- creating basic stuff to work on them
3
+ create database cheatsheet ;
4
+ use cheatsheet;
5
+
6
+ create table city
7
+ (
8
+ id int primary key ,
9
+ name varchar (17 ),
10
+ countrycode varchar (3 ),
11
+ district varchar (20 ),
12
+ population int
13
+ );
14
+
15
+ insert into city values (6 , " Rotterdam" , " NLD" , " Zuid-Holland" , 593321 );
16
+ insert into city values (3878 , " Scottsdale" , " USA" , " Arizona" , 202705 );
17
+ insert into city values (3965 , " Corona" , " USA" , " California" , 124966 );
18
+ insert into city values (3973 , " Concord" , " USA" , " California" , 121780 );
19
+ insert into city values (3977 , " Cedar Rapids" , " USA" , " Iowa" , 120758 );
20
+ insert into city values (3982 , " Coral Springs" , " USA" , " Florida" , 117549 );
21
+ insert into city values (4054 , " Fairfield" , " USA" , " California" , 92256 );
22
+ insert into city values (4058 , " Boulder" , " USA" , " Colorado" , 91238 );
23
+ insert into city values (4061 , " Fall River" , " USA" , " Massachusetts" , 90555 );
24
+
25
+ -- sum function
26
+ select sum (population) from city group by population;
27
+
28
+ -- average function
29
+ select avg (population) from city group by population;
30
+
31
+ -- count function
32
+ select count (name) from city group by name;
33
+
34
+ -- maximum function
35
+ select max (population) from city group by population;
36
+
37
+ -- minimum function
38
+ select min (population) from city group by population;
39
+
40
+ -- standard deviation function
41
+ select stddev(population) from city group by population;
42
+
43
+ -- group concat function
44
+ select group_concat(population) from city group by population;
0 commit comments