首页 > 解决方案 > 按国家/地区分组,带有桥接表

问题描述

我不太确定使用下表编写返回具有社区的国家/地区的查询。桥接表CommunityLocation是我可以查找公司及其位置但不太确定如何真正塑造此查询的地方。

Community
  community_id

Location
  location_id
  country_id

Country
  country_id

CommunityLocation
  community_id
  location_id

所以我只需要一个包含社区的国家 ID 列表。

标签: sqldatabase

解决方案


我认为这是你需要的:

select distinct
   c.country_id 
from 
   countires c
join Location l
   on c.country_id = l.country_id
join CommunityLocation cl
   on cl.location_id = l.location_id

推荐阅读