Re: Conditional Count with multiple expressions
- From: Stefan Hoffmann <ste5an@xxxxxxxxx>
- Date: Tue, 13 Oct 2009 17:32:50 +0200
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 <--
.
- Follow-Ups:
- Re: Conditional Count with multiple expressions
- From: JDubs
- Re: Conditional Count with multiple expressions
- From: JDubs
- Re: Conditional Count with multiple expressions
- References:
- Conditional Count with multiple expressions
- From: JDubs
- Conditional Count with multiple expressions
- Prev by Date: Re: Null Values in Queries
- Next by Date: Can You Figure Out What's Wrong W/ This Query
- Previous by thread: Conditional Count with multiple expressions
- Next by thread: Re: Conditional Count with multiple expressions
- Index(es):
Relevant Pages
|