Postgres 9.5 Materialized View from a table with jsonb columns
You just need to GROUP BY the product to build the sum() of the quantities of the products.

CREATE MATERIALIZED VIEW products
AS
SELECT "content"-&gt;'items'-&gt;&gt;'product' "product",
       sum(("content"-&gt;'items'-&gt;&gt;'qty')::integer) "quantity"
       FROM "my_table"
       GROUP BY "content"-&gt;'items'-&gt;&gt;'product';