Group by ids in many-to-many relationship and another column

Group by ids in many-to-many relationship and another column

I have two tables that are related by a many to many relationship. Here's a sample:

CREATE TABLE a (
a_id SERIAL PRIMARY KEY,
a_category NUMERIC NOT NULL,
a_value NUMERIC NOT NULL,
...