I’m trying to write a simple aggregate query, but struggling with something.
I have a table with a status field that is either ‘Complete’ or ‘Incomplete’.
I want the query to return three rows : the number of complete, number of incomplete, and a calculated percentage of completion.
So far I have the first two rows as
SELECT Status, Count(*) as countNums FROM tblStuff GROUP BY Status
So this would return something like
Status Countnums
__________
Complete 100
Incomplete 100
And what I want is
Status Countnums Percent
__________
Complete 100 50
Incomplete 100 50
OR
Status Countnums
__________
Complete 100
Incomplete 100
percentComplete 50
Although, I don’t see how the latter would work at a row level.
This is in MS Access.
You can use your existing
GROUP BYquery as a subquery and cross join that with another subquery which returns the total count fromtblStuff. Use the subquery values to derive[Percent]in the parent query.This worked (correct result; no syntax error) with Access 2007:
Beware that
Percentis a reserved word. Using it as an alias without surrounding it in square brackets threw an error.