-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial3_aggregateFunctions.sql
More file actions
61 lines (46 loc) · 1.83 KB
/
tutorial3_aggregateFunctions.sql
File metadata and controls
61 lines (46 loc) · 1.83 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*you can calculate things using SQL*/
/*COUNT = count(*)*/
/*GROUP BY = group by ...*/
/*FOR EXAMPLE: select column1, count(*) from table1 group by column1;*/
/*SUM = sum(columnName)*/
/*MAX = max(columnName)*/
/*MIN = min(columnName)*/
/*AVERAGE = avg(columnName)*/
/*ROUND TO n DIGITS= round(number, n)*/
/*ROUND TO INTEGER= round(number)*/
select * from fake_apps;
/*COUNT how many entries there are*/
select count(*) from fake_apps;
/*COUNT how many entries there are, but only those that fall under a condition*/
select count(*) from fake_apps
where price = 0;
/*show entries in column, and counts of each type of entry (based on GROUPs in a column)*/
select price, count(*) from fake_apps
group by price;
/*...now add a condition:*/
select price, count(*) from fake_apps
where downloads > 20000
group by price;
/*sum up the numbers in a column*/
select sum(downloads) from fake_apps;
/*get MAX in a column*/
select max(downloads) from fake_apps;
/*get max in a column, as well as values for other corresponding columns*/
select name, category, max(downloads) from fake_apps
group by category;
/*get MIN in a column*/
select min(downloads) from fake_apps;
/*get min in a column, as well as values for other corresponding columns*/
select name, category, min(downloads) from fake_apps
group by category;
/*get AVERAGE in a column*/
select avg(downloads) from fake_apps;
/*get average in a column, as well as values for other corresponding column*/
select price, avg(downloads) from fake_apps
group by price;
/*get average in a column (ROUNDed to 2 digits), as well as values for other corresponding column*/
select price, round(avg(downloads), 2) from fake_apps
group by price;
/*get average in a column (ROUNDed to INTEGER), as well as values for other corresponding column*/
select price, round(avg(downloads)) from fake_apps
group by price;