Skip to content

Commit

Permalink
Add solution for Basic Select domain
Browse files Browse the repository at this point in the history
  • Loading branch information
jivan99 committed Jul 25, 2021
1 parent 586e273 commit 954ff20
Show file tree
Hide file tree
Showing 20 changed files with 195 additions and 19 deletions.
25 changes: 25 additions & 0 deletions Basic Select/10_weather_observation_station_5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(
SELECT
city,
LENGTH(city)
FROM
station
ORDER BY
LENGTH(city),
city
LIMIT
1
)
UNION
(
SELECT
city,
LENGTH(city)
FROM
station
ORDER BY
LENGTH(city) DESC,
city
LIMIT
1
);
19 changes: 19 additions & 0 deletions Basic Select/11_weather_observation_station_6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- USING LIKE
SELECT
DISTINCT city
FROM
station
WHERE
city LIKE 'a%'
OR city LIKE 'e%'
OR city LIKE 'i%'
OR city LIKE 'O%'
OR city LIKE 'u%';

-- USING REGEXP
SELECT
DISTINCT city
FROM
station
WHERE
city REGEXP '^[a, e, i, o, u].*';
19 changes: 19 additions & 0 deletions Basic Select/12_weather_observation_station_7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- USING LIKE
SELECT
DISTINCT city
FROM
station
WHERE
city LIKE '%a'
OR city LIKE '%e'
OR city LIKE '%i'
OR city LIKE '%o'
OR city LIKE '%u';

-- USING REGEXP
SELECT
DISTINCT city
FROM
station
WHERE
city REGEXP '.*[a, e, i, o, u]$';
16 changes: 16 additions & 0 deletions Basic Select/13_weather_observation_station_8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- USING REGEXP
SELECT
DISTINCT city
FROM
station
WHERE
city REGEXP '^[a,e,i,o,u].*[a,e,i,o,u]$';

-- USING STRING FUNCTION
SELECT
DISTINCT city
FROM
station
WHERE
LEFT(city, 1) IN ('a', 'e', 'i', 'o', 'u')
and RIGHT(city, 1) IN ('a', 'e', 'i', 'o', 'u');
15 changes: 15 additions & 0 deletions Basic Select/14_weather_observation_station_9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- USING REGEXP
SELECT
DISTINCT city
FROM
station
WHERE
city NOT REGEXP '^[a, e, i, o, u].*';

-- USING STRING FUNCTIONS
SELECT
DISTINCT city
FROM
station
WHERE
LEFT(city, 1) NOT IN ('a', 'e', 'i', 'o', 'u');
6 changes: 6 additions & 0 deletions Basic Select/15_weather_observation_station_10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
DISTINCT city
FROM
station
WHERE
RIGHT(city, 1) NOT IN ('a', 'e', 'i', 'o', 'u');
7 changes: 7 additions & 0 deletions Basic Select/16_weather_observation_station_12.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT
DISTINCT city
FROM
station
WHERE
LEFT(city, 1) NOT IN ('a', 'e', 'i', 'o', 'u')
AND RIGHT(city, 1) NOT IN ('a', 'e', 'i', 'o', 'u');
9 changes: 9 additions & 0 deletions Basic Select/17_higher_than_75_marks.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT
name
FROM
students
WHERE
marks > 75
ORDER BY
SUBSTRING(name, -3, 3),
id;
6 changes: 6 additions & 0 deletions Basic Select/18_employee_names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
name
FROM
employee
ORDER BY
name;
9 changes: 9 additions & 0 deletions Basic Select/19_employee_salaries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT
name
FROM
employee
WHERE
(salary > 2000)
AND (months < 10)
ORDER BY
employee_id;
4 changes: 4 additions & 0 deletions Basic Select/1_revising_the_select_query_I.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT *
FROM city
WHERE countrycode = 'USA'
AND population > 100000;
4 changes: 4 additions & 0 deletions Basic Select/2_revising_the_select_query_II.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT NAME
FROM city
WHERE countrycode = 'USA'
AND population > 120000;
2 changes: 2 additions & 0 deletions Basic Select/3_select_all.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT *
FROM city;
3 changes: 3 additions & 0 deletions Basic Select/4_select_by_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT *
FROM city
WHERE id = 1661;
3 changes: 3 additions & 0 deletions Basic Select/5_japanese_cities_attributes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT *
FROM city
WHERE countrycode = 'JPN';
6 changes: 6 additions & 0 deletions Basic Select/6_japanese_cities_names.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
name
FROM
city
WHERE
countrycode = 'JPN';
5 changes: 5 additions & 0 deletions Basic Select/7_weather_observation_station_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT
city,
state
FROM
station;
6 changes: 6 additions & 0 deletions Basic Select/8_weather_observation_station_3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
DISTINCT city
FROM
station
WHERE
id % 2 = 0;
12 changes: 12 additions & 0 deletions Basic Select/9_weather_observation_station_4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SELECT
(
SELECT
COUNT(*)
FROM
station
) - (
SELECT
COUNT(DISTINCT city)
FROM
station
);
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ The solutions to all the HackerRank SQL Track Challenges on MySQL Environment.

|S.N.|Challenge |Solution|
|----|----------|--------|
|1.|[Revising the Select Query I](https://www.hackerrank.com/challenges/revising-the-select-query)||
|2.|[Revising the Select Query II](https://www.hackerrank.com/challenges/revising-the-select-query-2)||
|3.|[Select All](https://www.hackerrank.com/challenges/select-all-sql)||
|4.|[Select By ID](https://www.hackerrank.com/challenges/select-by-id)||
|5.|[Japanese Cities' Attributes](https://www.hackerrank.com/challenges/japanese-cities-attributes)||
|6.|[Japanese Cities' Names](https://www.hackerrank.com/challenges/japanese-cities-name)||
|7.|[Weather Observation Station 1](https://www.hackerrank.com/challenges/weather-observation-station-1)||
|8.|[Weather Observation Station 3](https://www.hackerrank.com/challenges/weather-observation-station-3)||
|9.|[Weather Observation Station 4](https://www.hackerrank.com/challenges/weather-observation-station-4)||
|10.|[Weather Observation Station 5](https://www.hackerrank.com/challenges/weather-observation-station-5)||
|11.|[Weather Observation Station 6](https://www.hackerrank.com/challenges/weather-observation-station-6)||
|12.|[Weather Observation Station 7](https://www.hackerrank.com/challenges/weather-observation-station-7)||
|13.|[Weather Observation Station 8](https://www.hackerrank.com/challenges/weather-observation-station-8)||
|14.|[Weather Observation Station 9](https://www.hackerrank.com/challenges/weather-observation-station-9)||
|15.|[Weather Observation Station 10](https://www.hackerrank.com/challenges/weather-observation-station-10)||
|16.|[Weather Observation Station 12](https://www.hackerrank.com/challenges/weather-observation-station-12)||
|17.|[Higher Than 75 Marks](https://www.hackerrank.com/challenges/more-than-75-marks)||
|18.|[Employee Names](https://www.hackerrank.com/challenges/name-of-employees)||
|19.|[Employee Salaries](https://www.hackerrank.com/challenges/salary-of-employees)||
|1.|[Revising the Select Query I](https://www.hackerrank.com/challenges/revising-the-select-query)|[Solution](/Basic%20Select/1_revising_the_select_query_I.sql)|
|2.|[Revising the Select Query II](https://www.hackerrank.com/challenges/revising-the-select-query-2)|[Solution](/Basic%20Select/2_revising_the_select_query_II.sql)|
|3.|[Select All](https://www.hackerrank.com/challenges/select-all-sql)|[Solution](/Basic%20Select/3_select_all.sql)|
|4.|[Select By ID](https://www.hackerrank.com/challenges/select-by-id)|[Solution](/Basic%20Select/4_select_by_id.sql)|
|5.|[Japanese Cities' Attributes](https://www.hackerrank.com/challenges/japanese-cities-attributes)|[Solution](/Basic%20Select/5_japanese_cities_attributes.sql)|
|6.|[Japanese Cities' Names](https://www.hackerrank.com/challenges/japanese-cities-name)|[Solution](/Basic%20Select/6_japanese_cities_names.sql)|
|7.|[Weather Observation Station 1](https://www.hackerrank.com/challenges/weather-observation-station-1)|[Solution](/Basic%20Select/7_weather_observation_station_1.sql)|
|8.|[Weather Observation Station 3](https://www.hackerrank.com/challenges/weather-observation-station-3)|[Solution](/Basic%20Select/8_weather_observation_station_3.sql)|
|9.|[Weather Observation Station 4](https://www.hackerrank.com/challenges/weather-observation-station-4)|[Solution](/Basic%20Select/9_weather_observation_station_4.sql)|
|10.|[Weather Observation Station 5](https://www.hackerrank.com/challenges/weather-observation-station-5)|[Solution](/Basic%20Select/10_weather_observation_station_5.sql)|
|11.|[Weather Observation Station 6](https://www.hackerrank.com/challenges/weather-observation-station-6)|[Solution](/Basic%20Select/11_weather_observation_station_6.sql)|
|12.|[Weather Observation Station 7](https://www.hackerrank.com/challenges/weather-observation-station-7)|[Solution](/Basic%20Select/12_weather_observation_station_7.sql)|
|13.|[Weather Observation Station 8](https://www.hackerrank.com/challenges/weather-observation-station-8)|[Solution](/Basic%20Select/13_weather_observation_station_8.sql)|
|14.|[Weather Observation Station 9](https://www.hackerrank.com/challenges/weather-observation-station-9)|[Solution](/Basic%20Select/14_weather_observation_station_9.sql)|
|15.|[Weather Observation Station 10](https://www.hackerrank.com/challenges/weather-observation-station-10)|[Solution](/Basic%20Select/15_weather_observation_station_10.sql)|
|16.|[Weather Observation Station 12](https://www.hackerrank.com/challenges/weather-observation-station-12)|[Solution](/Basic%20Select/16_weather_observation_station_12.sql)|
|17.|[Higher Than 75 Marks](https://www.hackerrank.com/challenges/more-than-75-marks)|[Solution](/Basic%20Select/17_higher_than_75_marks.sql)|
|18.|[Employee Names](https://www.hackerrank.com/challenges/name-of-employees)|[Solution](/Basic%20Select/18_employee_names.sql)|
|19.|[Employee Salaries](https://www.hackerrank.com/challenges/salary-of-employees)|[Solution](/Basic%20Select/19_employee_salaries.sql)|
## Advanced Select

|S.N.|Challenge |Solution|
Expand Down

0 comments on commit 954ff20

Please sign in to comment.