【问题标题】:Access Query and attributes访问查询和属性
【发布时间】:2019-02-27 13:46:27
【问题描述】:

设置是这样的:每个位置都有许多不同的帐户。有些是仅供应商帐户,有些则不是。每个帐户都有许多与之关联的账单。

我需要做以下两件事之一:

在位置表中创建一个动态属性,它将告诉我该位置是否与一个(或多个)仅作为供应商的帐户相关联。应该是真/假属性。

创建一个查询,该查询将返回与仅供应商帐户关联的所有位置的所有账单。我不想要只从供应商账户返回账单的查询。

感谢您的帮助!

【问题讨论】:

  • 这里的大多数人都希望样本表数据(和预期结果)为格式化文本,而不是图像(或图像链接)。
  • 您的问题是什么?你在解决问题的过程中遇到了什么问题?请发布尝试的代码、任何错误/不想要的结果以及想要的结果。

标签: sql ms-access


【解决方案1】:

答案如下:

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;

【讨论】:

    【解决方案2】:

    您可以在不涉及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)
    

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 2016-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-12
      • 2011-05-12
      • 2022-07-06
      相关资源
      最近更新 更多