Solutions
HackerRank
HackerRank
  • Home
  • 👨🏻‍💻 Profile
  • Prepare
    • Linux Shell
      • Bash
    • Python
      • Introduction
    • SQL
      • Basic Select
      • Advanced Select
      • Aggregation
      • Basic Join
  • Tutorials
    • 10 Days of Javascript
      • Day 0
      • Day 1
      • Day 2
      • Day 3
  • Certify
    • C# (Basic)
    • JavaScript (Basic)
    • SQL (Basic)
    • Rest API (Intermediate)
Powered by GitBook
On this page
  • Population Census
  • African Cities
  • Average Population of Each Continent
  • The Report

Was this helpful?

  1. Prepare
  2. SQL

Basic Join

PreviousAggregationNext10 Days of Javascript

Last updated 2 years ago

Was this helpful?

Population Census

select sum(ct.POPULATION) from CITY ct, COUNTRY cntry
where ct.COUNTRYCODE = cntry.CODE
and cntry.CONTINENT = 'Asia';

African Cities

select ct.NAME from CITY ct, COUNTRY cntry
where ct.COUNTRYCODE = cntry.CODE
and cntry.CONTINENT = 'Africa';

Average Population of Each Continent

select COUNTRY.CONTINENT, floor(avg(CITY.POPULATION))
from CITY, COUNTRY
where CITY.COUNTRYCODE = COUNTRY.CODE
group by COUNTRY.CONTINENT;

The Report

SELECT 
    CASE WHEN Grades.Grade<8 THEN NULL ELSE Students.Name END,
    Grades.Grade,
    Students.Marks
FROM Students JOIN Grades 
ON Students.Marks BETWEEN Grades.Min_Mark AND Grades.Max_Mark
ORDER BY Grades.Grade DESC, Students.Name, Students.Marks
LogoPopulation Census | HackerRankHackerRank
LogoAfrican Cities | HackerRankHackerRank
LogoAverage Population of Each Continent | HackerRankHackerRank
LogoThe Report | HackerRankHackerRank