Sql question

In my rails application I want to run something like a report

my table is like this

id
custommer_id
oranges
lemons

Select sum(oranges),sum(lemons) from my table
group by " MAGIC GOES HERE "
order by custommer_id

MAGIC GOES HERE = group by 3 registers…

like
this
id| customer_id | oranges | lemons
1 | 1 | 5 | 6 |
2 | 1 | 4 | 5 |
3 | 2 | 4 | 5 |
4 | 2 | 2 | 2 |
5 | 2 | 7 | 5 |
6 | 1 | 3 | 1 |
6 | 1 | 4 | 3 |

will result
id| customer_id | oranges | lemons
1 | 1 | 12 | 12 |
1 | 1 | 4 | 3 |
2 | 1 | 13 | 12 |

tks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs