title: How can I determine a score result based on the goal count in mysql?
body: <p>Maybe this question is super specific but I can't really find a way to do it.
  A bit of background. I'm studying, and In order to learn this I'm playing around counting stats from our Wednesday football matches with my friends.</p>
  <p>Now in order to make data as normalized as possible and calculate everything programmatically, I have a table called matches and a table called goals.</p>
  <p>Matches</p>
  <pre><code>+----+------------+
  | id | date       |
  +----+------------+
  | 1  | 05-01-2022 |
  +----+------------+
  | 2  | 12-01-2022 |
  +----+------------+
  
  </code></pre>
  <p>Goals</p>
  <pre><code>+----+--------------+
  | id | match | team |
  +----+--------------+
  | 1  |   1   |  A   |
  +----+--------------+
  | 2  |   1   |  B   |
  +----+--------------+
  | 3  |   1   |  B   |
  +----+--------------+
  | 4  |   2   |  A   |
  +----+--------------+
  | 5  |   2   |  A   |
  +----+--------------+
  
  </code></pre>
  <p>So my objective here is to count the goals for each team in each match, compare both values to determine the winner and come up with a result like this:</p>
  <p>Results</p>
  <pre><code>+-------+------------+
  | match | result     |
  +-------+------------+
  | 1     | B          |
  +-------+------------+
  | 2     | A          |
  +-------+------------+
  
  </code></pre>
  <p>I'm currently doing this fairly straightforward using laravel on my app, but I'm trying to get it done through SQL queries only.</p>
  <p>I also know that this would be much easier, if i simply added a goals_team_a, goals_team_b, result columns to my Matches table. If this is the actual correct solution is super easy to add, I just though at some point goals may differ from the score because of a typo or something and this is the way to be extra sure. Probably an overkill</p>