设置是这样的:每个位置都有许多不同的帐户。有些是供应商专用帐户,有些则不是。每个帐户都有许多与之相关的账单。
我需要做以下两件事之一:
在位置表中创建一个动态属性,该属性将告诉我该位置是否与仅作为供应商的一个或多个帐户关联。应该是true / false属性。
OR
创建一个查询,该查询将返回与仅供应商帐户关联的所有地点的所有账单。我不希望查询仅返回仅供应商帐户的账单。
感谢您的帮助!
答案 0 :(得分:0)
这是答案:
Location3PS查询:
SELECT DISTINCT Locations.Number
FROM Locations INNER JOIN Accounts ON Locations.Number = Accounts.[Location Num]
WHERE (((Accounts.[Supplier Only?])=True));
最终查询以获取帐单:
SELECT Bills.*, Location3PS.*
FROM
Location3PS INNER JOIN
(
Locations INNER JOIN
(
Accounts INNER JOIN Bills
ON Accounts.[Account Number] = Bills.[Account Number]
)
ON Locations.Number = Accounts.[Location Num]
)
ON Location3PS.Number = Locations.Number;
答案 1 :(得分:0)
您可以在不涉及Locations
表的情况下完成此操作,例如:
select b.* from
(bills b inner join accounts a on b.[account number] = a.[account number])
inner join
(select distinct c.[location num] from accounts c where c.[supplier only?] = true) l
on a.[location num] = l.[location num]
或者,您可以使用相关的子查询,例如:
select b.*
from bills b inner join accounts a on b.[account number] = a.[account number]
where exists
(select 1 from accounts c where c.[location num] = a.[location num] and c.[supplier only?] = true)