簡體   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