繁体   English   中英

查询以找到资产表中至少具有一个值的地区

[英]Query to find districts with at least one value in assets table

这是我的SQL查询:

select count(*) from district

但我只想选择存储表资产中至少具有1个值的所有区。 (可以大于1)

所以

select all districts that have at least 1 entry in assets

表资产:ID名称district_id

表区ID名称

我怎样才能做到这一点?

select count(*)
from district
where exists (
    select 1
    from assets
    where district_id = district.id
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM