Re: Conditional Count with multiple expressions
- From: JDubs <JDubs@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 15 Oct 2009 07:57:01 -0700
Thanks for your help. I got that to work, but I want to take it one step
further.
How can include percentages for each of the individual group as well as the
whole?
My results table will be big, but it would ideally look like this:
JobType Group A % Group B % Total %
Parts 100% 0% 66%
Repair 0% 100% 50%
Is that even possible? I know I"m pushing my luck. Thanks.
"Stefan Hoffmann" wrote:
hi,.
JDubs wrote:
I have a table that looks somewhat like this:This should work:
Group JobType JobStatus
A Parts Complete
A Repair New
A Parts Complete
B Repair Complete
B Parts New
I want to query a count of a certain JobStatus for each JobType i.e.
JobStatus="Complete", also a count all of the Jobs and then calculate a
percentage for jobs complete CountOfCompleteJobStatus/CountOfTotalJobs AS
JobStatusPercent. I'd like to group by JobType.
SELECT Q.[JobType],
Nz(R.[Completed], 0) / Q.[Total] AS [Percentage]
FROM
(
SELECT [JobType],
Count(*) AS [Total]
FROM [yourTable]
GROUP BY [JobType]
) Q
LEFT JOIN
(
SELECT [JobType],
Count(*) AS [Completed]
FROM [yourTable]
WHERE [JobStatus] = "Completed"
GROUP BY [JobType]
) R ON R.[JobType] = Q.[JobType]
mfG
--> stefan <--
- References:
- Conditional Count with multiple expressions
- From: JDubs
- Re: Conditional Count with multiple expressions
- From: Stefan Hoffmann
- Conditional Count with multiple expressions
- Prev by Date: Re: A UNION query would seem to be the desired result... - John W. Vinson
- Next by Date: Re: Conditional Count with multiple expressions
- Previous by thread: Re: Conditional Count with multiple expressions
- Next by thread: Re: Conditional Count with multiple expressions
- Index(es):
Relevant Pages
|