leflic leflic - 4 months ago 18
MySQL Question

Summarize a table where some fiels are null values

I've got an MySQL table that looks that way:

enter image description here

Now I want to group the three values on the right, so that there are no null values left.
So, in total, in this example I would have two rows, each filled with values.

I tried a lot with group statements, but it never goes the way I want.
Any Ideas?


You can aggregate your table according to records sharing the same t1qrid, start, and ende values. Then use the aggregate function SUM to combine the other three columns. Note that SUM will ignore NULL values, which seems to be the behavior you want.

SELECT t1qrid,
       SUM(Result) AS Result,
       SUM(InclLeft) AS InclLeft,
       SUM(InclRight) AS InclRight
FROM yourTable
GROUP BY t1qrid,