title: Cells are merged in a Query which asks different sums
body: <p>I have a database of cars with the Columns &quot;Plate&quot;, &quot;Type&quot; (0 for cars, 1 for trucks, and so on), &quot;Horsepower&quot;, &quot;Color&quot;, &quot;Emission Standard&quot; (Euro 0, Euro 1, and so on, but the field is just INT), &quot;Travelled distance&quot;.</p>
  <p>I want to get a table that groups all the vehicles by &quot;Type&quot;, &quot;Horsepower&quot;, &quot;Color&quot; and the sum of the travelled distance of Euro 0 category of that type/horsepower/Color, the sums for euro 1 category, the sum for euro 2 category etc.</p>
  <p>EDIT:
  as suggested, I'm reporting the exact table I have, and the exact results</p>
  <p>This is the table:
  <a href="https://i.stack.imgur.com/lPA9e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lPA9e.png" alt="(I enlightened two rows to point the matter" /></a></p>
  <p>The query is</p>
  <pre><code>SELECT type, horsepower, Color, if(emission_category = 0, round(sum(travelled_distance),3), null) as EURO0, if(emission_category = 1, round(sum(travelled_distance),3), null) as EURO1, if(emission_category = 2, round(sum(travelled_distance),3), null) as EURO2, if(emission_category = 3, round(sum(travelled_distance),3), null) as EURO3, if(emission_category = 4, round(sum(travelled_distance),3), null) as EURO4, if(emission_category = 5, round(sum(travelled_distance),3), null) as EURO5, if(emission_category = 6, round(sum(travelled_distance),3), null) as EURO6 FROM database_verde.veichles GROUP BY type, horsepower, Color
  </code></pre>
  <p>Instead of getting two different scores for the columns EURO 3 and 4, the two rows enlightened in the previous picture are merged in a single column</p>
  <p><a href="https://i.stack.imgur.com/hQt5y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hQt5y.png" alt="The enlightened row should have two different scores" /></a></p>
  <p>What am I doing wrong? How do I set the condition to sum ONLY if the row fits all the requirements?</p>