我在 ACE.OLEDB 中开发了以下 Microsoft Query:
SELECT
Name, Country
(SELECT COUNT(*)
FROM Table1 as T1
WHERE Name = T.Name
AND Country = T.Country
AND Description="Work"
GROUP BY Name, Country) / COUNT(*)
FROM
Table1 as T
GROUP BY
Name, Country
该查询工作正常,但在 Excel 中的 90k 多条记录上执行将永远持续下去。
是否可以通过使用COUNTIF
等效项来优化此查询?
我想象如果它像这样工作,查询可以被优化:
SELECT
Name, Country,
COUNTIF(CASE WHEN Description="Work" THEN 1 ELSE 0 END) / COUNT(*)
FROM
Table1 as T
GROUP BY
Name, Country
为了回复您对 CASE WHEN 的建议,我尝试了一个简单的概念证明查询:
SELECT SUM(CASE WHEN Description="Work" THEN 1 ELSE 0 END)
FROM (SELECT "Work" as Description)
我得到一个Unrecognized keyword WHEN
错误。