diff --git a/African Cities.pgsql b/African Cities.pgsql new file mode 100644 index 0000000..1dcebae --- /dev/null +++ b/African Cities.pgsql @@ -0,0 +1 @@ +SELECT city.NAME FROM CITY INNER JOIN country on CITY.COUNTRYCODE=COUNTRY.CODE WHERE COUNTRY.CONTINENT='Africa'; diff --git a/Average Population.pgsql b/Average Population.pgsql new file mode 100644 index 0000000..6c26722 --- /dev/null +++ b/Average Population.pgsql @@ -0,0 +1,2 @@ +select floor (avg(population)) +from city ; diff --git a/Higher Than 75 Marks.pgsql b/Higher Than 75 Marks.pgsql new file mode 100644 index 0000000..719e442 --- /dev/null +++ b/Higher Than 75 Marks.pgsql @@ -0,0 +1 @@ +SELECT NAME FROM STUDENTS WHERE MARKS>75 ORDER BY RIGHT(NAME,3),ID ASC; diff --git a/Japanese Cities' Names.pgsql b/Japanese Cities' Names.pgsql new file mode 100644 index 0000000..460d53e --- /dev/null +++ b/Japanese Cities' Names.pgsql @@ -0,0 +1,10 @@ + +/* + Enter your query here and follow these instructions: + 1. Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error. + 2. The AS keyword causes errors, so follow this convention: "Select t.Field From table1 t" instead of "select t.Field From table1 AS t" + 3. Type your code immediately after comment. Don't leave any blank line. +*/ +SELECT NAME +FROM CITY +WHERE COUNTRYCODE = 'JPN'; diff --git a/PopulationCensus.pgsql b/PopulationCensus.pgsql new file mode 100644 index 0000000..73bb41f --- /dev/null +++ b/PopulationCensus.pgsql @@ -0,0 +1,2 @@ +--https://www.hackerrank.com/challenges/asian-population/problem?utm_campaign=challenge-recommendation&utm_medium=email&utm_source=24-hour-campaign +select sum(c.population) from city as c,country as ct where C.CountryCode=Ct.Code and CONTINENT = 'Asia'; diff --git a/Population_density.pgsql b/Population_density.pgsql new file mode 100644 index 0000000..6c64eb8 --- /dev/null +++ b/Population_density.pgsql @@ -0,0 +1 @@ +SELECT MAX(POPULATION)- MIN(POPULATION) FROM CITY; diff --git a/Revising Aggregations - The Count Function.pgsql b/Revising Aggregations - The Count Function.pgsql new file mode 100644 index 0000000..9c98b17 --- /dev/null +++ b/Revising Aggregations - The Count Function.pgsql @@ -0,0 +1,3 @@ +select count(Population) +from CITY +where Population>100000; diff --git a/Revising Aggregations.pgsql b/Revising Aggregations.pgsql new file mode 100644 index 0000000..5e7389c --- /dev/null +++ b/Revising Aggregations.pgsql @@ -0,0 +1,2 @@ +--https://www.hackerrank.com/challenges/revising-aggregations-sum/problem +select sum(population) from city where district="California" ; diff --git a/Revising the Select Query II.txt b/Revising the Select Query II.pgsql similarity index 65% rename from Revising the Select Query II.txt rename to Revising the Select Query II.pgsql index 7f4e661..f187c3a 100644 --- a/Revising the Select Query II.txt +++ b/Revising the Select Query II.pgsql @@ -1,3 +1,3 @@ SELECT NAME FROM CITY WHERE COUNTRYCODE='USA' -AND POPULATION>=120000; \ No newline at end of file +AND POPULATION>=120000; diff --git a/Revising the Select Query I.txt b/Revising the Select Query.pgsql similarity index 65% rename from Revising the Select Query I.txt rename to Revising the Select Query.pgsql index 855bb06..2ec931f 100644 --- a/Revising the Select Query I.txt +++ b/Revising the Select Query.pgsql @@ -1,3 +1,3 @@ SELECT * FROM City WHERE CountryCode ='USA' -AND POPULATION>100000; \ No newline at end of file +AND POPULATION>100000; diff --git a/The PADS.pgsql b/The PADS.pgsql new file mode 100644 index 0000000..bf533a7 --- /dev/null +++ b/The PADS.pgsql @@ -0,0 +1,3 @@ +--https://www.hackerrank.com/challenges/the-pads/problem +select concat(name,'(',left(OCCUPATION,1),')') from OCCUPATIONS order by name; +select concat('There are a total of ',count(OCCUPATION),' ',lower(OCCUPATION),'s.') from OCCUPATIONS group by OCCUPATION order by count(OCCUPATION); diff --git a/Top Earners.txt b/Top Earners.pgsql similarity index 100% rename from Top Earners.txt rename to Top Earners.pgsql diff --git a/Type of Triangle.pgsql b/Type of Triangle.pgsql new file mode 100644 index 0000000..529b39a --- /dev/null +++ b/Type of Triangle.pgsql @@ -0,0 +1,11 @@ +SELECT CASE +WHEN A+B>C AND A+C>B AND B+C>A THEN +CASE +WHEN A=B AND A=C THEN 'Equilateral' +WHEN A=B OR B=C OR A=C THEN 'Isosceles' +ELSE 'Scalene' +END + +ELSE 'Not A Triangle' +END +FROM TRIANGLES; diff --git a/Weather Observation Station 12.pgsql b/Weather Observation Station 12.pgsql new file mode 100644 index 0000000..dd52f29 --- /dev/null +++ b/Weather Observation Station 12.pgsql @@ -0,0 +1,6 @@ +/* +Enter your query here. +*/ +select distinct city +from station +where city regexp '^[^aeiou].*[^aeiou]$'; diff --git a/Weather Observation Station 18.pgsql b/Weather Observation Station 18.pgsql new file mode 100644 index 0000000..2ffd5e6 --- /dev/null +++ b/Weather Observation Station 18.pgsql @@ -0,0 +1 @@ +select round((max(lat_n)-min(lat_n))+(max(long_w)-min(long_w)),4) from station; diff --git a/Weather Observation Station 5.pgsql b/Weather Observation Station 5.pgsql new file mode 100644 index 0000000..c7c95d0 --- /dev/null +++ b/Weather Observation Station 5.pgsql @@ -0,0 +1,5 @@ +--https://www.hackerrank.com/challenges/weather-observation-station-5/problem +select city , length(city) from station +order by length(city) ,city limit 1; +select city , length(city) from station +order by length(city) desc, city limit 1; diff --git a/binary-tree-node.pgsql b/binary-tree-node.pgsql new file mode 100644 index 0000000..3922729 --- /dev/null +++ b/binary-tree-node.pgsql @@ -0,0 +1 @@ +SELECT N, IF(P IS NULL,’Root’,IF((SELECT COUNT(*) FROM BST WHERE P=B.N)>0,’Inner’,’Leaf’)) FROM BST AS B ORDER BY N; diff --git a/draw_the_triangle1.pgsql b/draw_the_triangle1.pgsql new file mode 100644 index 0000000..bd88718 --- /dev/null +++ b/draw_the_triangle1.pgsql @@ -0,0 +1,2 @@ +set @num= 21; +select repeat('* ', @num := @num -1) from information_schema.tables; diff --git a/draw_the_triangle2.pgsql b/draw_the_triangle2.pgsql new file mode 100644 index 0000000..fcdcdb8 --- /dev/null +++ b/draw_the_triangle2.pgsql @@ -0,0 +1,2 @@ +set @num=0; +select repeat('* ', @num := @num+1) from information_schema.tables LIMIT 20; diff --git a/select_by_id.pgsql b/select_by_id.pgsql new file mode 100644 index 0000000..7128803 --- /dev/null +++ b/select_by_id.pgsql @@ -0,0 +1,2 @@ +SELECT * FROM CITY +WHERE ID="1661";