Jump to content

[SOLVED] Ratio With Count() and Group By?


josborne

Recommended Posts

I have spent the whole day trying to figure this out and have realized I need help.

 

First:

 

SELECT Version( ) 

5.0.67-community


CREATE TABLE `Results_tbl` (
`Race_ID` int(10) NOT NULL,
`Season` year(4) NOT NULL,
`Rac` varchar(3) NOT NULL default 'RAC',
`Rider_ID` int(5) NOT NULL,
`Position` int(2) default NULL,
`Points` int(2) NOT NULL default '0',
`Race_Time` time default NULL,
`MSecs` char(5) default NULL,
`DNS` binary(1) NOT NULL,
`DNF` binary(1) NOT NULL,
`Outcome` varchar(7) default 'FIN'
) ENGINE=MyISAM DEFAULT CHARSET=latin1

 

 

I am trying to find the ratio of DNF's by each Rider_ID. It is easy to find the ratio for a single rider using:

 

SELECT
(SELECT COUNT(DNF) FROM Results_tbl 
WHERE DNF=1 and Rider_ID = 1 )/(SELECT COUNT(DNF) FROM Results_tbl WHERE Rider_ID = 1 ) AS Ratio

 

However, what I am trying to do is get the ratio for all Rider_IDs as with a GROUP BY

 

As in:

 

Rider_ID 	Ratio
---------+------
1 	     |  .54
2 	     |  .55
3 	     |  .35
4 	     |  .15
5 	     |  .05
6 	     |  .54
7 	     |  .24


 

 

Any help would be greatly appreciated. I am finding my self breaking into tears at regular intervals as I try to figure this out.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.