'Group by into single json colum

Using SQL I'd like to convert a table that looks like this

id col11 col2
1 a b
1 c d
2 e f
2 g h

Into something that looks like this:

id combined
1 [{col1: a, col2:b}, {col1: c, col2:d}]
1 [{col1: e, col2:f}, {col1: g, col2:h}]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source