Skip to content

Commit 28c0496

Browse files
committed
aggregation and updated readme
1 parent 34461cf commit 28c0496

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,41 @@ select e.fname, p.pname from employees as e left outer join project as p on e.ei
212212
#### Right outer join
213213
```sql
214214
select e.fname, p.pname from employees as e right outer join project as p on e.eid = p.eid;
215-
```
215+
```
216+
217+
## Aggregation
218+
219+
#### Sum function
220+
```sql
221+
select sum(population) from city group by population;
222+
```
223+
224+
#### Average function
225+
```sql
226+
select avg(population) from city group by population;
227+
```
228+
229+
#### Count function
230+
```sql
231+
select count(name) from city group by name;
232+
```
233+
234+
#### Maximum function
235+
```sql
236+
select max(population) from city group by population;
237+
```
238+
239+
#### Minimum function
240+
```sql
241+
select min(population) from city group by population;
242+
```
243+
244+
#### Standard deviation function
245+
```sql
246+
select stddev(population) from city group by population;
247+
```
248+
249+
#### Group concat function
250+
```sql
251+
select group_concat(population) from city group by population;
252+
```

aggregation.sql

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

Comments
 (0)