using SUM on foreign view's keys grouped on multiple key/values?
You barely got it, once you have unnested the arrays you can simply aggregate the result by building.id, name and level in this way:

WITH ct AS
(
  SELECT 
    buildings.id AS building_id
    ,buildings.name AS building_name
    ,jsonb_array_elements( document -&gt; 'levels' ) -&gt; 'meta' -&gt;&gt; 'level_number' AS level_number
    ,((jsonb_array_elements(jsonb_array_elements(buildings.document-&gt;'levels')-&gt;'rooms')-&gt;'meta')-&gt;&gt;'sqft')::numeric AS sqft
  FROM 
    buildings
)
SELECT
    building_id, building_name, level_number,
    SUM(sqft) AS sqft
FROM
    ct
GROUP BY
    building_id, building_name, level_number;




building_id | building_name | level_number | sqft
----------: | :------------ | :----------- | ---:
          1 | my blding     | 0            | 1300
          1 | my blding     | 1            | 1800



db&lt;>fiddle here