Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using GROUP BY to find percentages 1

Status
Not open for further replies.

sorkIndustries

Technical User
May 14, 2009
6
US
In table UserInfo, I have three fields: Users, Requests, and Approvals. For each user, I want to find the percentage of requests that are approved. Here is some sample data:

User|Request|Approval
----+---------+--------
A Y Y
B N N
C Y N
A N N
B Y Y
B Y N
C Y Y
A N N
A Y N

So, for each user, I want to find total "Y" approvals divided by total "Y" requests.

I've tried this using:

select User,100*count([Approval]="Y")/count([Request]="Y") as [Success Rate] from UserInfo group by User;

It doesn't work. I just get 100% for every user.

How can I get the query to list the users and their percentages?
 
Code:
Select User, Sum(IIF([Approval] = "Y", 1, 0)) / Sum(IIF([Request] = "Y", 1, 0)) as Approve_Factor
From UserInfo
Group By User
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top