Weather Observation Station 4

Sort by

recency

|

1454 Discussions

|

  • + 0 comments

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

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

  • + 0 comments

    Hello here is the code to solve the problem

    there are two ways to compute the difference between: 1. total number of CITY entries (including duplicates) 2. number of distinct CITY entries.

    Assuming the table is named STATION and the column is CITY First method: 1. SQL to get the difference directly

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

    Second method: 2.If you want to see the two counts separately (total vs distinct) and compute the difference in a single result:

    SELECT
      total_city AS total_city_entries,
      distinct_city AS distinct_city_entries,
      total_city - distinct_city AS city_duplicate_diff
    FROM (
      SELECT
        COUNT(CITY) AS total_city,
        COUNT(DISTINCT CITY) AS distinct_city
      FROM STATION
    ) AS t;
    
  • + 0 comments

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

  • + 0 comments

    SELECT (count(city) - count(distinct city)) AS CITY from station

  • + 0 comments

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