title: The percentage of occurrences of a field per ID
body: <p>I am making a website for a game as a hobby and I want to add a win percentage for every champion in it. I track every match in my DB and the outcome column can be 0 or 1 for loss or win. I am using MySql. I want my outcome table to be like this:</p>
  
  <pre><code>ChampID | Wins | Loss | Percentage
  12        1      1      50%
  13        2      0      100%
  </code></pre>
  
  <p>My Matches table looks like this:</p>
  
  <pre><code>MatchID | ChampID | PlayerID | MatchOutcome
  1         12        1231       1
  2         12        1414       0
  3         13        1341       1
  4         13        1512       1
  </code></pre>
  
  <p>So the champion with ID 12 will have 50% win rate while 13 will have 100%.</p>
  
  <p>I have been trying unions and joins but I couldn't get them right, this is the closest I have come.</p>
  
  <pre><code>SELECT
  (SELECT COUNT(*) FROM Matches WHERE (MatchOutcome LIKE "0")) AS Loss,
  (SELECT COUNT(*) FROM Matches WHERE (MatchOutcome LIKE "1")) AS Win, 
  (SELECT (Win/(Win+Loss))*100 ) AS Percentage
  </code></pre>
  
  <p>This method seems the most promising as I would also like to be able to sort further by PlayerID. </p>
  
  <p>Thanks for your time</p>