sql—两条select语句的减法

rsaldnfx  于 2021-07-27  发布在  Java
关注(0)|答案(2)|浏览(312)

我有一张简单的table:
街区

code neighbourhood country

有些国家有相同的邻里名称。我想要的只是总数减去唯一的。但我和接线员有问题;这就是我要做的。

select count(*)- select distinct(neighbourhood) from Neighbourhood
pinkon5k

pinkon5k1#

所以你想:

select count(*) - count(distinct neighbourhood)
from Neighbourhood;

我可以建议进一步细分:

select cnt, count(*), min(neighbourhood), max(neighbourhood)
from (select neighbourhood, count(*) as cnt
      from neighbourhood
      group by neighbourhood
     ) n
group by cnt
order by cnt;

这显示了复制的频率和示例值 neighbourhood .

dffbzjpn

dffbzjpn2#

使用 count(distinct neighbourhood) 以及 distinct 不是函数

select count(*)- select count(distinct neighbourhood) from Neighbourhood

相关问题