感谢您对我上一个问题的回答。我希望可以这样做,但我现在有另一个相关的问题:
我现在被要求扩展我正在做的事情,包括将以当地货币持有的 GrossCost 转换为 GBP 的基础货币。
我分别拥有这两个部分的 SQL,但不知道如何组合它们。这两部分是:
获取每家公司的 GrossCost 总和:
Select Cast(ROW_NUMBER() OVER (ORDER BY Sum(JobCosting.PurchaseOrderItems.GrossCost) Desc) AS Int) As 'RowNum', Admin.Companies.UniqueName As 'UN', Sum(JobCosting.PurchaseOrderItems.GrossCost) As 'DonutValue' From Admin.Companies Inner Join JobCosting.PurchaseOrders On Admin.Companies.CompanyId = JobCosting.PurchaseOrders.SupplierCompanyId Inner Join JobCosting.PurchaseOrderItems On JobCosting.PurchaseOrders.PurchaseOrderId = JobCosting.PurchaseOrderItems.PurchaseOrderId Where UniqueName Like 'HH %' Group By UniqueName Order By 'DonutValue' Desc
获取每种货币的货币兑换率。换算为相关货币的总成本 * 汇率。这是汇率 SQL(由 SQLGRL 提供 - 再次感谢):
SELECT * FROM (SELECT CompanyId, UniqueName,CurrencyCode,ExchangeRate,FromCurrencyID, ToCurrencyId, ActiveDate, rank() OVER (partition BY UniqueName,Admin.Currencies.CurrencyId ORDER BY ActiveDate DESC) AS Rank FROM Admin.Companies INNER JOIN Admin.Currencies ON Admin.Companies.CurrencyId = Admin.Currencies.CurrencyId INNER JOIN Admin.CurrencyRates ON Admin.Currencies.CurrencyId = Admin.CurrencyRates.FromCurrencyId WHERE Admin.CurrencyRates.ToCurrencyId = 47) ci
WHERE ci.Rank = 1
我需要做的是最终得到一个组合 SQL,它获取所有相同的行并计算每家公司 GrossSales 总和的转换值。
同样,任何帮助都会非常感激,因为我真的被困住了。
提前致谢