You can do it in SQL, stop writing extra code for that – Geshan’s Blog

Use SQL to do math like sum, average etc. Utilize it for grouping one to many relational values like getting categories of product. Leverage SQL for string manipulation like using CONCAT_WS for…