I have a parent row and then many child rows, and I must aggregate statistics from these child rows.
For a more concrete example let's imagine I have one round of golf (parent row) and then child rows with the score of each hole. I need to aggregate statistics on these rows, like number of birdies, pars, bogies, putts and so forth. And then put these numbers in a round_detail table.
What would be the best solution to this?
I'm using postgres if it matters, but this is probably just a general sql propblem.
EDIT: As requested http://sqlfiddle.com/#!1/6549c
CREATE TABLEfor the tables involved and some sample data. Ideally as a runnable exampel on sqlfiddle.com – a_horse_with_no_name Feb 7 at 16:11