简体   繁体   English

MS Access SQL 中带有多值字段的参数弹出问题

[英]Problem with paramter popup with multi-value field in MS Access SQL

I have the following SQL query:我有以下 SQL 查询:

FROM Registration AS r
WHERE r.RegisteredFor.Value=[Forms]![RunQueries]![filterBy];

When I run this query it reports back fine, however, when I run a second query which uses this query, so for example:但是,当我运行此查询时,它会报告正常,但是,当我运行使用此查询的第二个查询时,例如:

SELECT reg.Gender, Count(reg.Gender) AS CountOfGender, 
    Round(Count(reg.Gender)*100/(SELECT COUNT(ID) FROM FirstQuery),1) AS Percentage
FROM FirstQuery AS reg
GROUP BY reg.Gender;

It always either pops up a parameter box asking for "r.RegisteredFor.Value", or alternatively if I try tweaking things, it starts complaining about aggregate functions in the "Percentage" part.它总是弹出一个参数框询问“r.RegisteredFor.Value”,或者如果我尝试调整一些东西,它开始抱怨“百分比”部分中的聚合函数。

If I remove the r.RegisteredFor.Value from the WHERE, or replace it with something else everything works fine.如果我从 WHERE 中删除 r.RegisteredFor.Value ,或者用其他东西替换它,一切正常。 I've tried replacing the "=" in the first query WHERE with "in", and even used a SELECT to check these values on the RegisteredFor linked table, but nothing stops the parameter box from popping up.我尝试将第一个查询 WHERE 中的“=”替换为“in”,甚至使用 SELECT 在 RegisteredFor 链接表上检查这些值,但没有什么能阻止参数框弹出。

Hmmm.嗯。 . . . . You might consider conditional aggregation instead.您可能会考虑使用条件聚合。 Assuming you have two genders, "M" and "F" :假设您有两种性别, "M""F"

SELECT SUM(IIF(reg.Gender = "M", 1, 0)) AS m_cnt,
       SUM(IIF(reg.Gender = "F", 1, 0)) AS f_cnt,
       AVG(IIF(reg.Gender = "M", 100.0, 0)) AS m_percent,
       AVG(IIF(reg.Gender = "F", 100.0, 0)) AS f_percent
FROM FirstQuery AS reg;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM