Pavithra's Space
  • Home
  • Skills
    • SQL
    • HackerRank
      • 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
Powered by GitBook
On this page
  1. Skills
  2. HackerRank

Weather Observation Station 4

PreviousWeather Observation Station 3NextWeather Observation Station 5

Last updated 1 year ago

Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.

The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.

For example, if there are three records in the table with CITY values 'New York', 'New York', 'Bengalaru', there are 2 different city names: 'New York' and 'Bengalaru'. The query returns , because .

Sol:

SELECT COUNT(CITY) - COUNT(DISTINCT CITY) FROM STATION;

Explanation:

  • SELECT COUNT(CITY) - COUNT(DISTINCT CITY): This part of the query calculates the difference between two counts:

    • COUNT(CITY): This counts the total number of entries in the CITY column.

    • COUNT(DISTINCT CITY): This counts the number of distinct (unique) entries in the CITY column. By subtracting the count of distinct city entries from the total count of city entries, we get the difference.

    • FROM STATION: This specifies the table from which we want to retrieve the data, which is the STATION table.

Weather Observation Station 4 | HackerRankHackerRank
Logo