DSum()域作为子查询?

时间:2014-01-06 20:16:59

标签: sql function ms-access subquery

我运行此查询:

SELECT
job_code_desc,
SumOfDowntime AS DowntimeTotal,
Round(DSum("[SumofDowntime]","DT","[SumOfDowntime]>=" & [DowntimeTotal] & "")/DSum("[SumOfdowntime]","DT"),3) AS CumPct

FROM
  (SELECT 
  pareto_downtime_detail_tbl.job_code_desc, 
  Sum(pareto_downtime_detail_tbl.downtime) AS SumOfDowntime

  FROM 
  pareto_downtime_detail_tbl

  WHERE
  (((pareto_downtime_detail_tbl.job_code_desc) Not Like "*break*" 
  AND (pareto_downtime_detail_tbl.job_code_desc) Not Like "*prep*"))

  GROUP BY 
  pareto_downtime_detail_tbl.job_code_desc) AS DT;

并收到错误:

  

Microsoft Access数据库引擎找不到输入表或   查询'DT'。确保它存在并且其名称拼写   正确“。

DSum()函数的域是否可以来自子查询?或者它必须从“永久”表或查询调用?当我将子查询(DT)保存为永久查询并运行上面的查询时,

SELECT 
pareto_lift_downtime_detail_qry.job_code_desc, 
pareto_lift_downtime_detail_qry.SumOfdowntime AS DowntimeTotal, 
Round(DSum("[SumofDowntime]","pareto_lift_downtime_detail_qry","[SumOfDowntime]>=" & [DowntimeTotal] & "")/DSum("[SumOfdowntime]","pareto_lift_downtime_detail_qry"),3) AS CumPct

FROM 
pareto_lift_downtime_detail_qry;

它成功运行,但性能明显滞后。然后,我使用新查询pareto_lift_downtime_detail_qry作为生成表查询,然后引用此新表。这可以以适当的速度完成我想要的,但我有2个理由不使用make-table查询。我希望尽可能保持这个文件的有序性,这个数据每周都会由具有少量Access知识和零查询/数据库经验的职员刷新,因此她不会每周都进行新的make-table查询。

1 个答案:

答案 0 :(得分:1)

“DSum()函数的域可以来自子查询吗?”

没有

“或者必须从”永久“表或查询中调用吗?”