How to Implement Group By Query in Strapi for Counting Orders by Shirt Color?

Hello,

I am using Strapi as my backend and have a requirement to count the number of orders based on the color of the shirts ordered. The colors are red, yellow, and blue. The default Strapi API does not support GROUP BY type queries out of the box. Could anyone guide me on how to implement this using custom controllers or any other method within Strapi?

Here’s what the model structure looks like:

Order model
id (order ID)
shirt_color (color of the shirt, a string)
I need to create an endpoint that returns the count of orders grouped by the shirt_color. Any suggestions or examples would be greatly appreciated!

Thank you!

This topic has been created from a Discord post (1234184909346832405) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord