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
  • Revising the Select Query I
  • Revising the Select Query II
  • Select All
  • Select By ID
  • Japanese Cities' Attributes
  • Japanese Cities' Names
  • Weather Observation Station 1
  • Weather Observation Station 3
  • Weather Observation Station 4
  • Weather Observation Station 5
  • Weather Observation Station 6
  • Weather Observation Station 7
  • Weather Observation Station 8
  • Weather Observation Station 9
  • Weather Observation Station 10
  • Weather Observation Station 11
  • Weather Observation Station 12
  • Higher Than 75 Marks
  • Employee Names
  • Employee Salaries

Was this helpful?

  1. Prepare
  2. SQL

Basic Select

PreviousSQLNextAdvanced Select

Last updated 2 years ago

Was this helpful?

Revising the Select Query I

select * from CITY
where POPULATION > 100000
and COUNTRYCODE = 'USA';

Revising the Select Query II

select NAME from CITY
where POPULATION > 120000
and COUNTRYCODE = 'USA';

Select All

select * from CITY;

Select By ID

select * from CITY
where ID = 1661;

Japanese Cities' Attributes

select * from CITY 
where COUNTRYCODE = 'JPN';

Japanese Cities' Names

select NAME from CITY
where COUNTRYCODE = 'JPN';

Weather Observation Station 1

select CITY, STATE from STATION;

Weather Observation Station 3

select distinct CITY from STATION
where mod(ID, 2) = 0;

Weather Observation Station 4

select count(CITY) - count(distinct CITY) from STATION;

Weather Observation Station 5

select CITY, length(CITY) from(
    select CITY from STATION 
    order by length(CITY), CITY asc) 
where rownum = 1; 

select CITY, length(CITY) from(
    select CITY from STATION 
    order by length(CITY) desc) 
where rownum = 1;

Weather Observation Station 6

select distinct CITY from STATION
where lower(substr(CITY,1,1)) in ('a','e','i','o','u');

Weather Observation Station 7

select distinct CITY from STATION
where lower(substr(CITY,-1,1)) in ('a','e','i','o','u');

Weather Observation Station 8

select distinct CITY from STATION 
where lower(substr(CITY,1,1)) in ('a','e','i','o','u')
and lower(substr(CITY,-1,1)) in ('a','e','i','o','u');

Weather Observation Station 9

select distinct CITY from STATION 
where lower(substr(CITY,1,1)) not in ('a','e','i','o','u');

Weather Observation Station 10

select distinct CITY from STATION
where lower(substr(CITY,-1,1)) not in ('a','e','i','o','u');

Weather Observation Station 11

select distinct CITY from STATION
where lower(substr(CITY,1,1)) not in ('a','e','i','o','u')
or lower(substr(CITY,-1,1)) not in ('a','e','i','o','u');

Weather Observation Station 12

select distinct CITY from STATION
where lower(substr(CITY,1,1)) not in ('a','e','i','o','u')
and lower(substr(CITY,-1,1)) not in ('a','e','i','o','u');

Higher Than 75 Marks

select Name from STUDENTS
where Marks > 75
order by substr(Name,-3,3), ID asc;

Employee Names

select name from Employee
order by name asc;

Employee Salaries

select name from Employee
where salary > 2000
and months < 10
order by employee_id asc;
LogoJapanese Cities' Names | HackerRankHackerRank
LogoSelect All | HackerRankHackerRank
LogoRevising the Select Query II | HackerRankHackerRank
LogoRevising the Select Query I | HackerRankHackerRank
LogoSelect By ID | HackerRankHackerRank
LogoJapanese Cities' Attributes | HackerRankHackerRank
LogoWeather Observation Station 1 | HackerRankHackerRank
LogoWeather Observation Station 4 | HackerRankHackerRank
LogoWeather Observation Station 7 | HackerRankHackerRank
LogoWeather Observation Station 3 | HackerRankHackerRank
LogoWeather Observation Station 5 | HackerRankHackerRank
LogoWeather Observation Station 9 | HackerRankHackerRank
LogoWeather Observation Station 11 | HackerRankHackerRank
LogoWeather Observation Station 12 | HackerRankHackerRank
LogoWeather Observation Station 6 | HackerRankHackerRank
LogoWeather Observation Station 10 | HackerRankHackerRank
LogoHigher Than 75 Marks | HackerRankHackerRank
LogoEmployee Names | HackerRankHackerRank
LogoWeather Observation Station 8 | HackerRankHackerRank
LogoEmployee Salaries | HackerRankHackerRank