vinayakb | 38b7ca4 | 2012-03-05 05:44:15 +0000 | [diff] [blame] | 1 | declare function calculate($events){ |
| 2 | for $event in $events |
| 3 | for $sponsor in $event.sponsoring_sigs |
| 4 | let $es := { "event": $event, "sponsor": $sponsor } |
| 5 | group by $sig_name := $sponsor.sig_name with $es |
| 6 | let $sig_sponsorship_count := count($es) |
| 7 | let $by_chapter := |
| 8 | for $e in $es |
| 9 | group by $chapter_name := $e.sponsor.chapter_name with $es |
| 10 | return { "chapter_name": $chapter_name, "escount" : count($es) } |
| 11 | order by $sig_sponsorship_count desc |
| 12 | limit 5 |
| 13 | return { "sig_name": $sig_name, "total_count": $sig_sponsorship_count, "chapter_breakdown": $by_chapter } |
| 14 | } |
| 15 | |
| 16 | let $result := calculate(dataset('Events')) |
| 17 | return $result |