我正在尝试从Access数据库中按国家/地区列出特定年份和特定国家/地区的前5名客户。
我到此为止,查询就会运行。
SELECT Data.Year, Data.HarmonizedCustomerName, Sum(Data.[Total Revenue - USD])
FROM Data
WHERE Year = 2019 and (Country = "SE" OR Country = "GB" or Country = "FR" OR Country = "NO" OR Country = "GE") AND Data.HarmonizedCustomerName IN
(SELECT TOP 5 HarmonizedCustomerName FROM
(SELECT Country, Year, HarmonizedCustomerName, Sum([Total Revenue - USD]) AS TotRev FROM Data
WHERE Year = 2019 and (Country = "SE" OR Country = "GB" or Country = "FR" OR Country = "NO" OR Country = "GE") GROUP BY Year, Country, HarmonizedCustomerName) AS T1
WHERE T1.Country = Data.Country AND T1.Year = Data.Year
ORDER BY TotRev DESC)
GROUP BY Year, Country, HarmonizedCustomerName
我已经将其运行了15分钟,但这太长了,我还没有看到任何结果。有更有效的方法吗?
Data table looks like this (sample)
这被标记为重复问题-但是我已经尝试了建议的解决方案,实际上这是我上面查询的基础,但是我无法使其在合理的时间内运行。