我在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
在回复给你的建议的情况下,我尝试了一个简单的概念证明查询:
SELECT SUM(CASE WHEN Description="Work" THEN 1 ELSE 0 END)
FROM (SELECT "Work" as Description)
我收到Unrecognized keyword WHEN
错误。
答案 0 :(得分:1)
伯爵只计算事情。你应该做一个SUM
SUM(CASE WHEN Description="Work" THEN 1 ELSE 0 END)
如果不起作用,则总和为0,否则为1。
查看您的代码,提及Excel。您可能需要将其更改为
SUM( IIF( Description="Work", 1, 0) )