I'm new to SQL, wasn't able to write the correct SQL. Given a table STATION that holds data for five fields namely ID, CITY, STATE, NORTHERN LATITUDE and WESTERN LONGITUDE.
我是SQL的新手,无法编写正确的SQL。给定一个表STATION,其中包含五个字段的数据,即ID,CITY,STATE,NORTHERN LATITUDE和WESTERN LONGITUDE。
+-------------+------------+
| Field | Type |
+-------------+------------+
| ID | INTEGER |
| CITY | VARCHAR(21)|
| STATE | VARCHAR(2) |
| LAT_N | NUMERIC |
| LONG_W | NUMERIC |
+-------------+------------+
Let NUM
be the number of cities and NUMunique
be the number of unique cities, then write a query to print the value of NUM
- NUMunique
.
设NUM为城市数,NUMunique为唯一城市数,然后编写查询以打印NUM - NUMunique的值。
I tried:
我试过了:
select (count(CITY)- distinct count(CITY)) from STATION;
3 个解决方案
#1
20
You can use the select distinct inside the count and try this way
您可以在计数内使用select distinct并尝试这种方式
select (count(CITY)- count(distinct CITY)) from STATION;
#2
0
SELECT COUNT(CITY) - COUNT(DISTINCT CITY) AS N FROM STATION
SELECT COUNT(CITY) - COUNT(DISTINCT CITY)作为N FROM FROM STATION
#3
-1
SELECT (COUNT(CITY)- COUNT(DISTINCT(CITY))) AS diff
FROM STATION
#1
20
You can use the select distinct inside the count and try this way
您可以在计数内使用select distinct并尝试这种方式
select (count(CITY)- count(distinct CITY)) from STATION;
#2
0
SELECT COUNT(CITY) - COUNT(DISTINCT CITY) AS N FROM STATION
SELECT COUNT(CITY) - COUNT(DISTINCT CITY)作为N FROM FROM STATION
#3
-1
SELECT (COUNT(CITY)- COUNT(DISTINCT(CITY))) AS diff
FROM STATION