Need help on a query to sum all values by month grouped by comma
Trying:
SELECT GROUP_CONCAT( (
SELECT SUM( price )
FROM sales
GROUP BY MONTH( date ) )
)
FROM sales
LIMIT 0 , 30
but returning: #1242 – Subquery returns more than 1 row
group_concat alone won’t help cause I need the sum of the values by month.
Any help? Thanks
Untested:
Note that you will get max 12 values, since any different years are merged. You probably want to add an
ORDER BYin the subquery to get the months in a defined order in the result.