[英]Query to find districts with at least one value in assets table
This is my SQL query: 这是我的SQL查询:
select count(*) from district
but i want to select only all districts that have at least 1 value in table assets stored. 但我只想选择存储表资产中至少具有1个值的所有区。 (can be more than 1)
(可以大于1)
so 所以
select all districts that have at least 1 entry in assets
table assets: id name district_id 表资产:ID名称district_id
table district id name 表区ID名称
How can I do that? 我怎样才能做到这一点?
select count(*)
from district
where exists (
select 1
from assets
where district_id = district.id
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.