查询表中非唯一元素的数量

时间:2022-08-24 04:19:51

Let NUM be the number of CITY entries in STATION, and NUMunique be the number of unique cities. Query the value of NUM−NUMunique from STATION.

设NUM为站内城市条目的个数,NUMunique为唯一城市的个数。查询NUM的值−NUMunique从站。

In other words, query the number of non-unique CITY names in STATION by subtracting the number of unique CITY entries in the table from the total number of CITY entries in the table, which has this structure:

换句话说,通过将表中唯一城市条目的数量减去表中所有城市条目的数量来查询车站中非唯一城市名称的数量。

查询表中非唯一元素的数量

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

LAT_N为北纬,LONG_W为西经。

I have this query but it returns the wrong output.

我有这个查询,但它返回了错误的输出。

SELECT SUM(COUNT(CITY)) 
FROM STATION 
GROUP BY CITY 
HAVING COUNT(CITY)>1; b

2 个解决方案

#1


2  

select count(*) - count(distinct uniquevalue) from table;

从表中选择count(*) - count(明显的惟一价值);

You need to determine an expression which identifies a city uniquely. Is it the name? Is it a combination of LAT_N and LONG_W? You might use something like (1000*LAT_N + LONG_W), for example.

您需要确定一个表达式,该表达式可以惟一地标识一个城市。是这个名字吗?它是LAT_N和LONG_W的组合吗?例如,您可以使用类似(1000*LAT_N + LONG_W)之类的东西。

#2


0  

Try the following query:

试试下面的查询:

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

#1


2  

select count(*) - count(distinct uniquevalue) from table;

从表中选择count(*) - count(明显的惟一价值);

You need to determine an expression which identifies a city uniquely. Is it the name? Is it a combination of LAT_N and LONG_W? You might use something like (1000*LAT_N + LONG_W), for example.

您需要确定一个表达式,该表达式可以惟一地标识一个城市。是这个名字吗?它是LAT_N和LONG_W的组合吗?例如,您可以使用类似(1000*LAT_N + LONG_W)之类的东西。

#2


0  

Try the following query:

试试下面的查询:

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