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:


SOLUTION:

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

Explanation:

  • COUNT(*) counts all rows (including duplicates and nulls in other columns, but not in CITY directly).

  • COUNT(DISTINCT CITY) counts unique cities only.

  • Subtracting the two gives you the number of duplicate city entries.

Popular posts from this blog

In this problem, you will practice your knowledge on interfaces - Hacker Rank Solution.