Note that there are some explanatory texts on larger screens.

plurals
  1. POCount the "ratio?" for wins and losses
    primarykey
    data
    text
    <p>I've already got this to work but it's a really bad approach and i need some help with factorization of my query.</p> <pre><code>SELECT `GameDate`, COUNT(CASE WHEN `P1Outcome`= 'win' AND P2Param = 'a' THEN 1 END) AS a_win, COUNT(CASE WHEN `P1Outcome`= 'loss' AND P2Param = 'a' THEN 1 END) AS a_loss, COUNT(CASE WHEN `P1Outcome`= 'win' AND P2Param = 'b' THEN 1 END) AS b_win, COUNT(CASE WHEN `P1Outcome`= 'loss' AND P2Param = 'b' THEN 1 END) AS b_loss FROM games WHERE `P2Param` IN ( 'a', 'b', 'c' ) GROUP BY GameDate </code></pre> <p>This will get me an query that i can use in my php application but i would like to skip having to make the actual ratio calculation in php and fetch it directly with SQL.</p> <p>So basically what i've been trying to do is something similar to this:</p> <pre><code> COUNT(CASE WHEN `P1Outcome`= 'win' AND P2Param = 'a' THEN 1 Else -1 END) AS a_ratio, </code></pre> <p>But just as the beginer i'm, i can't figure it out how i can make this to work. </p> <p><strong>EDIT:</strong> Sorry for not explaining my regards in more details, here is the thing. I'm creating an statistics component and i need to fetch the ratio for a period of time in order to display it as an graph. So the following things are required:</p> <p>GameDate (1,2,3,4... days ago) The ratio for the player based on to different params (maps in this case)</p> <p>So in short this is what i got at the moment:</p> <pre><code>GameDate a_win a_loss b_win b_loss 2011/04/25 x x x x 2011/04/23 x x x x .... </code></pre> <p>So everything works out great, but i would like to have the actual ratio calculation made in SQL because at the moment i need to make it in php e.g <code>$ratio = $q[a_win]-$q[a_loss]</code> and due to the fact that I've a lot of different param my query is like double the size because i need to fetch both the win and loss instead of just the ratio like i want in the first place.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload