【发布时间】:2021-12-12 19:09:34
【问题描述】:
我们有两个表用于“物理位置”和“商店”。一个物理位置可以有多个商店。每个商店都可以是活动的或非活动的。
我们如何编写查询来查找那些没有与之关联的活动商店的“物理位置”?
物理位置
LocationId LocationAddress
100 Address1
101 Address2
102 Address3
商店
StoreID LocationId Status
100A 100 Active
100B 100 Inactive
101C 101 Inactive
102D 101 Inactive
我尝试过类似下面的方法。
Select * from PhysicalLocation where LocationId IN
(Select LocationId from Store where Status <> 'Active')
我的预期结果是
LocationId LocationAddress
101 Address2
因为这个位置只有不活跃的商店
【问题讨论】:
标签: sql sql-server