I want to get the Creators of Artworks, GROUP BY by their role. I find a way to have the list of the Creators with their role, for each Artwork.
SELECT
JSON_OBJECT('id', a.IDartwork, 'creaDate', a.artworkCreationDate, 'length', a.length, 'summarize', a.summarize) AS artwork,
(SELECT JSON_ARRAYAGG(JSON_OBJECT('id', c.IDcreator, 'name', c.creatorName, 'role', r.roleName))
FROM AMEGA_creator c
JOIN AMEGA_artwork_creator ac ON c.IDcreator = ac.IDcreator
JOIN AMEGA_role r ON r.IDrole = ac.IDrole
WHERE ac.IDartwork = a.IDartwork) AS creators
FROM
AMEGA_artwork a;
But I can't get to use the GROUP BY
. I get the error:
Subquery returns more than 1 row
I can't find a solution. I want a result like that :
artworks creators
<art1> < <"director", <crea1, crea26>>, <"writer", <crea5, crea12>> >
<art2> < <"drawer", <crea23, crea8>> >
Here is the MLD structure :
Any idea ?
`SELECT JSON_ARRAYAGG(JSON_OBJECT('role', r.roleName, 'crea', JSON_ARRAYAGG(JSON_OBJECT('id', c.IDcreator, 'name', c.creatorName)))) FROM AMEGA_creator c JOIN AMEGA_artwork_creator ac ON c.IDcreator = ac.IDcreator JOIN AMEGA_role r ON r.IDrole = ac.IDrole WHERE ac.IDartwork = 2 GROUP BY ac.IDrole;`
But i get a 'invalid use of group by' error. – nikubik Jan 16 '23 at 16:13