I'm trying to summarize parts of a delivery in terms of weight (and also value) but I fail to make it work when I group by deliveryNo which is what I want/need. I also need to group by type to get correct summarizations in each columns which causes extra rows and I need 1 row per deliveryNo and I have tried several solutions with case and subequeries but I'm not managing to get this correct.
Example below. To clarify, the type is a value connected to each row from another table, and weight is also from a separate table but the tables are linked with an articleNo.
deliveryNo | type | amount | weight | value |
---|---|---|---|---|
123 | 1 | 5 | 1 | 25 |
123 | 2 | 10 | 1 | 26 |
123 | 3 | 2 | 2 | 24 |
123 | 4 | 8 | 2 | 20 |
123 | 5 | 6 | 3 | 10 |
What I want to achieve is this: (settling for weight but the value will be used, but I reckon the principal will be the same)
deliveryNo | weighttype1 | weighttype2 | weighttype3 | weightRest |
---|---|---|---|---|
123 | 5 | 10 | 4 | 34 |