buyingyi | 2fd7fa6 | 2014-11-24 19:31:55 -0800 | [diff] [blame] | 1 | declare function calculate($events){ |
| 2 | from $event in $events |
| 3 | from $sponsor in $event.sponsoring_sigs |
| 4 | with $es := { "event": $event, "sponsor": $sponsor } |
buyingyi | 3ca46d0 | 2015-01-27 23:22:09 -0800 | [diff] [blame^] | 5 | group by $sig_name := $sponsor.sig_name keeping $es |
buyingyi | 2fd7fa6 | 2014-11-24 19:31:55 -0800 | [diff] [blame] | 6 | with $sig_sponsorship_count := count($es) |
| 7 | with $by_chapter := |
| 8 | from $e in $es |
buyingyi | 3ca46d0 | 2015-01-27 23:22:09 -0800 | [diff] [blame^] | 9 | group by $chapter_name := $e.sponsor.chapter_name keeping $es |
buyingyi | 2fd7fa6 | 2014-11-24 19:31:55 -0800 | [diff] [blame] | 10 | select { "chapter_name": $chapter_name, "escount" : count($es) } |
| 11 | order by $sig_sponsorship_count desc |
| 12 | limit 5 |
| 13 | select { "sig_name": $sig_name, "total_count": $sig_sponsorship_count, "chapter_breakdown": $by_chapter } |
| 14 | } |
| 15 | |
| 16 | with $result := calculate(dataset('Events')) |
| 17 | select $result |