I have a table in postgresql that starts like this:
car_id part_ids total_inventory
------ -------- ----------
10134 101,506,589 50
12236 201,506,101 20
78865 201,399,304 10
I'm trying to write a query and/or view that will separate each of the part_ids on the comma, count the sum total_inventory together for each part_id, and then include all of the part_ids in a single column like this:
part_ids total_inventory
-------- ----------
101 70
506 70
589 50
201 30
399 10
304 10
I've tried using unnest(string_to_array) on the part_ids column to get the end result - but haven't had too much luck.
Anyone have any ideas? Thanks for helping!
P.S. this is my first question - any recommendations/edits please let me know