1select
2 q.sp_question_id,
3 count(p.project_id) as projectCount,
4 sum(p.funding) as amount,
5 round(sum(p.funding)/sum(sum(p.funding)) over() *100) as percentTotal
6from questions q
7 left join objectives o on
8 o.sp_question_id = q.sp_question_id
9 and o.fiscal_year = 2014
10 left join projects p on o.fiscal_year = p.fiscal_year and o.sp_objective_id = p.sp_objective_id
11 left join funders f on p.funder_id = f.funder_id and f.funder_short_name ='foo'
12where q.fiscal_year = 2014
13group by q.sp_question_id
14order by q.sp_question_id;
15