【发布时间】:2012-10-09 08:49:08
【问题描述】:
好的,这很复杂,但我对 Access 很陌生,所以也许这并不难。
我的数据库中有 3 个表:
客户 - 这包含基金所有客户的列表。其中一些客户在基金中拥有多个账户。结构:
ID | CliName
------------
1 | Joe Blogs Holdings
2 | John Doe Investments
etc...
ClientMap - 这基本上有一个所有帐户 的列表,另一个字段包含它属于哪个客户(拥有该帐户的客户的 ID)。
ID | AccountName | ClientName | ClientID (refs to ID in Clients)
------------
1 | Joe Blogs Safe Fund | Joe Blogs Holdings | 1
2 | Joe Blogs Risk Fund | Joe Blogs Holdings | 1
3 | John Doe Fund | John Doe Investments | 2
etc...
估值 - 这是每个账户在任何给定日期的价值列表。
ID | ValuationDate | Valuation | AccName
------------
1 | 30/09/2012 | 1,469,524 | Joe Blogs Safe Fund
2 | 30/09/2012 | 1,767,134 | Joe Blogs Risk Fund
3 | 30/09/2012 | 239,561 | John Doe Fund
4 | 30/06/2012 | 1,367,167 | Joe Blogs Safe Fund
5 | 30/06/2012 | 1,637,121 | Joe Blogs Risk Fund
6 | 30/06/2012 | 219,241 | John Doe Fund
好的,所以我想运行一个查询,列出从客户表中选择的客户,并返回他们所有账户的估值总和。例如。 John Doe 只有一个帐户,因此查询结果如下所示:
ClientName | ValuationDate | Valuation
----
John Doe Investments | 30/09/2012 | 239,561
John Doe Investments | 30/06/2012 | 219,241
但是,查询应该为 Joe Blogs 返回类似这样的内容:
ClientName | ValuationDate | Valuation
----
Joe Blogs Holdings | 30/09/2012 | 3,236,658
Joe Blogs Holdings | 30/06/2012 | 3,004,288
因此,对于添加的每个日期,它都会查找所有 Joe Blogs 帐户的总数,以提供总体估值。我该怎么做?
希望这很清楚,并且那些访问专家能够帮助我。 谢谢
到目前为止我有这个,但它并没有汇总每个日期的帐户,它只是单独列出它们:
SELECT ClientMap.AccName, Clients.ClientName, Valuations.ValuationDate, Valuations.Valuation
FROM (Clients INNER JOIN ClientMap ON Clients.ID = ClientMap.ClientID) INNER JOIN Valuations ON ClientMap.AccName = Valuations.AccName
WHERE (((Clients.ClientName) Like [Which Client?] & "*"));
【问题讨论】:
-
这看起来更像是一个一般的 SQL 问题而不是 Access 特定的问题,因此我在这里添加了 SQL 标记。