Give it to ChatGPT or claude and see how it handles that.
The aggregate node (Aggregate | n8n Docs) should work for this use-case.