MS Access - 提取单个值进行计算

时间:2015-02-23 10:35:11

标签: sql ms-access select nested

这是与MS Access相关的问题。

我将Collat​​eral分为50次,因为我的ExchangeRates表中有50行...但SELECT语句应该只提取与CurrencyCode =“EUR”相关的值。如何更改以下声明以仅将分割应用一次?

SELECT tbl_A.Security, tbl_A.Typ, Sum(([Collateral]/(SELECT tblExchangeRates.RateToUSD
FROM tblExchangeRates
WHERE (((tblExchangeRates.CurrencyCode)="EUR"))))) AS CollateralUSD
FROM tbl_A, tblExchangeRates
GROUP BY tbl_A.Security, tbl_A.Typ
HAVING (((tbl_A.Typ)="PR"));

1 个答案:

答案 0 :(得分:0)

看起来这是我愿意得到的,只是一个别名。 SQL大师,欢迎您查看。

SELECT tbl_A.Security, Sum(([Collateral]/[RateToUSD])) AS CollateralUSD
FROM tbl_A, (SELECT RateToUSD
    FROM tblExchangeRates
    WHERE CurrencyCode = 'EUR')  AS MyAliasQ
GROUP BY tbl_A.Security
HAVING (((tbl_A.Typ)="PR"));