I have a table called Projects with an AMOUNT column that is the revenue for that project. I would like to SUM all amounts for each year based on the CREATED_AT date so I can provide a yearly revenue summary.
I would like to see how using collections can simplify this.
It is "faster" in some regards, but much harder to debug the data being collected. Unless I am dealing with a large dataset (1000+ records) I prefer to use @burlresearch 's method.
This comes down to the amount of data being processed. The direct query is a very viable solution, and in the simplistics of this query I would not see anything wrong with the query. If it was a more complex query that has many points of error, it is sometimes better to give up a bit of speed and instead go with a more debuggable solution.
@cmdobueno in most cases it will be faster for SQL to do the sort than for you to fetch all the records and then sort in your app.. with 100 records you may not see a huge difference but there will always be a difference...
@burlresearch sure the OP said collection but usually when people answer they also try to give 'better' (or alternative) solution