Skip to content

Commit

Permalink
Add solution for Aggregation domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jivan99 committed Jul 26, 2021
1 parent 2a2c629 commit af1d39b
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 17 deletions.
7 changes: 7 additions & 0 deletions 03 Aggregation/10_weather_observation_station_13.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT
TRUNCATE(SUM(lat_n), 4)
FROM
station
WHERE
lat_n < 137.2345
AND lat_n > 38.7880;
6 changes: 6 additions & 0 deletions 03 Aggregation/11_weather_observation_station_14.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
TRUNCATE(MAX(lat_n), 4)
FROM
station
WHERE
lat_n < 137.2345;
10 changes: 10 additions & 0 deletions 03 Aggregation/12_weather_observation_station_15.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT
ROUND(long_w, 4)
FROM
station
WHERE
lat_n < 137.2345
ORDER BY
lat_n DESC
LIMIT
1;
10 changes: 10 additions & 0 deletions 03 Aggregation/13_weather_observation_station_16.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT
ROUND(lat_n, 4)
FROM
station
WHERE
lat_n > 38.7880
ORDER BY
lat_n
LIMIT
1;
10 changes: 10 additions & 0 deletions 03 Aggregation/14_weather_observation_station_17.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT
ROUND(long_w, 4)
FROM
station
WHERE
lat_n > 38.7880
ORDER BY
lat_n
LIMIT
1;
7 changes: 7 additions & 0 deletions 03 Aggregation/15_weather_observation_station_18.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT
ROUND(
(MAX(lat_n) - MIN(lat_n)) + (MAX(long_w) - MIN(long_w)),
4
)
FROM
station;
9 changes: 9 additions & 0 deletions 03 Aggregation/16_weather_observation_station_19.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT
FORMAT(
SQRT(
POWER((MAX(lat_n) - MIN(lat_n)), 2) + POWER((MAX(long_w) - MIN(long_w)), 2)
),
4
)
FROM
station;
19 changes: 19 additions & 0 deletions 03 Aggregation/17_weather_observation_station_20.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SET
@rowindex: = 0;
SELECT
ROUND(AVG(s.lat_n), 4)
FROM
(
SELECT
@rowindex: = @rowindex + 1 AS rowindex,
lat_n AS lat_n
FROM
station
ORDER BY
lat_n
) AS s
WHERE
s.rowindex in (
FLOOR((@rowindex + 1) / 2),
CEIL((@rowindex + 1) / 2)
);
6 changes: 6 additions & 0 deletions 03 Aggregation/1_revising_aggregations-the_count_function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
COUNT(*)
FROM
city
WHERE
population > 100000;
6 changes: 6 additions & 0 deletions 03 Aggregation/2_revising_aggregations-the_sum_function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
SUM(population)
FROM
city
WHERE
DISTRICT = 'California';
6 changes: 6 additions & 0 deletions 03 Aggregation/3_revising_aggregations-averages.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
AVG(population)
FROM
city
WHERE
district = 'California';
4 changes: 4 additions & 0 deletions 03 Aggregation/4_average_population.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
FLOOR(AVG(population))
FROM
city;
6 changes: 6 additions & 0 deletions 03 Aggregation/5_japan_population.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
SUM(population)
FROM
city
WHERE
countrycode = 'JPN';
4 changes: 4 additions & 0 deletions 03 Aggregation/6_population_density_difference.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
MAX(population) - MIN(population)
FROM
city;
6 changes: 6 additions & 0 deletions 03 Aggregation/7_the_blunder.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
CEIL(
AVG(salary) - AVG(CAST(REPLACE(salary, '0', '') AS SIGNED))
)
FROM
employees;
11 changes: 11 additions & 0 deletions 03 Aggregation/8_top_earners.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT
(salary * months) AS earning,
COUNT(*)
FROM
employee
GROUP BY
earning
ORDER BY
1 DESC
LIMIT
1;
5 changes: 5 additions & 0 deletions 03 Aggregation/9_weather_observation_station_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT
ROUND(SUM(lat_n), 2),
ROUND(SUM(long_w), 2)
FROM
STATION;
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,23 @@ The solutions to all the HackerRank SQL Track Challenges on MySQL Environment.

|S.N.|Challenge |Solution|
|----|----------|--------|
|1.|[Revising Aggregations - The Count Function](https://www.hackerrank.com/challenges/revising-aggregations-the-count-function)|[]()|
|2.|[Revising Aggregations - The Sum Function](https://www.hackerrank.com/challenges/revising-aggregations-sum)|[]()|
|3.|[Revising Aggregations - Averages](https://www.hackerrank.com/challenges/revising-aggregations-the-average-function)|[]()|
|4.|[Average Population](https://www.hackerrank.com/challenges/average-population)|[]()|
|5.|[Japan Population](https://www.hackerrank.com/challenges/japan-population)|[]()|
|6.|[Population Density Difference](https://www.hackerrank.com/challenges/population-density-difference)|[]()|
|7.|[The Blunder](https://www.hackerrank.com/challenges/the-blunder)|[]()|
|8.|[Top Earners](https://www.hackerrank.com/challenges/earnings-of-employees)|[]()|
|9.|[Weather Observation Station 2](https://www.hackerrank.com/challenges/weather-observation-station-2)|[]()|
|10.|[Weather Observation Station 13](https://www.hackerrank.com/challenges/weather-observation-station-13)|[]()|
|11.|[Weather Observation Station 14](https://www.hackerrank.com/challenges/weather-observation-station-14)|[]()|
|12.|[Weather Observation Station 15](https://www.hackerrank.com/challenges/weather-observation-station-15)|[]()|
|13.|[Weather Observation Station 16](https://www.hackerrank.com/challenges/weather-observation-station-16)|[]()|
|14.|[Weather Observation Station 17](https://www.hackerrank.com/challenges/weather-observation-station-17)|[]()|
|15.|[Weather Observation Station 18](https://www.hackerrank.com/challenges/weather-observation-station-18)|[]()|
|16.|[Weather Observation Station 19](https://www.hackerrank.com/challenges/weather-observation-station-19)|[]()|
|17.|[Weather Observation Station 20](https://www.hackerrank.com/challenges/weather-observation-station-20)|[]()|
|1.|[Revising Aggregations - The Count Function](https://www.hackerrank.com/challenges/revising-aggregations-the-count-function)|[Solution](/03%20Aggregation/1_revising_aggregations-the_count_function.sql)|
|2.|[Revising Aggregations - The Sum Function](https://www.hackerrank.com/challenges/revising-aggregations-sum)|[Solution](/03%20Aggregation/2_revising_aggregations-the_sum_function.sql)|
|3.|[Revising Aggregations - Averages](https://www.hackerrank.com/challenges/revising-aggregations-the-average-function)|[Solution](/03%20Aggregation/3_revising_aggregations-averages.sql)|
|4.|[Average Population](https://www.hackerrank.com/challenges/average-population)|[Solution](/03%20Aggregation/4_average_population.sql)|
|5.|[Japan Population](https://www.hackerrank.com/challenges/japan-population)|[Solution](/03%20Aggregation/5_japan_population.sql)|
|6.|[Population Density Difference](https://www.hackerrank.com/challenges/population-density-difference)|[Solution](/03%20Aggregation/6_population_density_difference.sql)|
|7.|[The Blunder](https://www.hackerrank.com/challenges/the-blunder)|[Solution](/03%20Aggregation/7_the_blunder.sql)|
|8.|[Top Earners](https://www.hackerrank.com/challenges/earnings-of-employees)|[Solution](/03%20Aggregation/8_top_earners.sql)|
|9.|[Weather Observation Station 2](https://www.hackerrank.com/challenges/weather-observation-station-2)|[Solution](/03%20Aggregation/9_weather_observation_station_2.sql)|
|10.|[Weather Observation Station 13](https://www.hackerrank.com/challenges/weather-observation-station-13)|[Solution](/03%20Aggregation/10_weather_observation_station_13.sql)|
|11.|[Weather Observation Station 14](https://www.hackerrank.com/challenges/weather-observation-station-14)|[Solution](/03%20Aggregation/11_weather_observation_station_14.sql)|
|12.|[Weather Observation Station 15](https://www.hackerrank.com/challenges/weather-observation-station-15)|[Solution](/03%20Aggregation/12_weather_observation_station_15.sql)|
|13.|[Weather Observation Station 16](https://www.hackerrank.com/challenges/weather-observation-station-16)|[Solution](/03%20Aggregation/13_weather_observation_station_16.sql)|
|14.|[Weather Observation Station 17](https://www.hackerrank.com/challenges/weather-observation-station-17)|[Solution](/03%20Aggregation/14_weather_observation_station_17.sql)|
|15.|[Weather Observation Station 18](https://www.hackerrank.com/challenges/weather-observation-station-18)|[Solution](/03%20Aggregation/15_weather_observation_station_18.sql)|
|16.|[Weather Observation Station 19](https://www.hackerrank.com/challenges/weather-observation-station-19)|[Solution](/03%20Aggregation/16_weather_observation_station_19.sql)|
|17.|[Weather Observation Station 20](https://www.hackerrank.com/challenges/weather-observation-station-20)|[Solution](/03%20Aggregation/17_weather_observation_station_20.sql)|

## Basic Join

Expand Down

0 comments on commit af1d39b

Please sign in to comment.