Reputation: 21091
I have table of payments with dates and comments:
id | summ | date | comment
I want to select list of values ordered by date and sum of them grouped by date. I know how to get sum of values grouped by date
SELECT date, sum(summ) GROUP BY date ORDER BY date
but i also want to select values.
for example if my table looks like
1 | 1200 | 24.05.2015 | apple
2 | 250 | 24.05.2015 | banana
3 | 700 | 27.05.2015 | peach
4 | 1350 | 27.05.2015 | lemon
3 | 120 | 29.05.2015 | grape
4 | 7350 | 30.05.2015 | grape and two apples
I want to receive
24.05.2015 | 1450 | apple 1200, banana 250
27.05.2015 | 2150 | peach 700, lemon 1350
29.05.2015 | 120 | grape 120
30.05.2015 | 7350 | grape and two apples 7350
Upvotes: 1
Views: 40
Reputation: 204746
SELECT date, sum(summ), group_concat(concat(comment, ' ', summ))
FROM your_table
GROUP BY date
ORDER BY date
Upvotes: 2