-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaggregations.sql
62 lines (47 loc) · 1.35 KB
/
aggregations.sql
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
62
select count(name)
from city
where population > 100000;
select sum(population)
from CITY
where district = 'California';
select avg(population)
from city
where district = 'California';
select floor(avg(population))
from city;
select sum(population)
from city
where countrycode='JPN';
select (max(population)-min(population))
from city;
select concat(round(sum(lat_n),2),' ',round(sum(long_w),2))
from station;
select truncate(sum(lat_n),4)
from station
where lat_n >38.7880 and lat_n< 137.2345;
select truncate(max(lat_n),4)
from station
where lat_n<137.2345;
select round(long_w,4)
from station
where lat_n<137.2345
order by lat_n DESC
limit 1;
select round(min(lat_n),4)
from station
where lat_n>38.7780;
select round(long_w,4)
from STATION
where lat_n>38.7780
order by lat_n ASC
limit 1;
select round(abs(min(lat_n)-min(long_w)) + abs(max(lat_n)-max(long_w)),4)
from station;
select round(sqrt(power((min(lat_n)-min(long_w)),2)+power((max(lat_n)-max(long_w)),2)),4)
from station;
select round(x.lat_n,4)
from station x, station y
group by x.lat_n
having sum(sign(y.lat_n-x.lat_n))=0; /**this gives correct median value as long as there's an odd number of values**/
select ceiling(avg(salary) - avg(replace(salary,'0','')))
from employees; /** replace treats salary like string, not integer. while average treats the result as an integer, not string**/