Deviopath › PostgreSQL

Products in Each Order

Medium · Strings

string_agg(value, separator) joins the values of a group into one text. Put an ORDER BY inside the call to control the order of the pieces: string_agg(name, ', ' ORDER BY name).

For every order that has items, return order_id, products (the product names joined with ', ', in alphabetical order) and total_quantity (sum of quantity). Sort by order_id.

Next: Totals by Status, Side by Side