简体   繁体   中英

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

I have the following SQL query:

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.

If I remove the r.RegisteredFor.Value from the WHERE, or replace it with something else everything works fine. 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.

Hmmm. . . You might consider conditional aggregation instead. Assuming you have two genders, "M" and "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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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