简体   繁体   English

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

[英]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.

相关问题 基于集合的查询,以查找表中包含至少一个空值的所有列 - Set-based query to find all columns in table that contain at least one null value 查询以查找一组列中至少一个值的出现 - Query to find occurrence of at least one value in a set of columns 按搜索量查找地区的 SQL 查询 - SQL query to find districts by search volume SQL查询以在一个表中查找重复项,但前提是至少有一个重复项具有位于不同表中的约会 - SQL Query to find duplicates in one table but only if at least one of the duplicates has an appointment which is in a different table SQL查询以查找至少一天的行数大于或等于阈值的用户的最小值和最大值 - SQL query to find min and & max value for a user who has at least one day with a row count of > threshold SQL:至少一个值存在于另一个表中 - SQL: At least one value exists in another table 列出至少有一行针对特定查询的具有非空值的表的列 - List columns of table on which there is at least one row with a non null value for a specific query SQL JOIN,当至少一个表包含所需的值时:可以在单个查询中实现吗? - SQL JOIN when at least one table contains the desired value: Can this be achieved in a single query? MS Access 查询输入必须包含至少一个表或查询 - MS Access Query Input must contain at least one table or query SQL查询以查找具有至少一个列出标签的文章 - SQL-query to find articles with at least one of the listed tags
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM