Skip to content
Snippets Groups Projects
Select Git revision
  • 9aa870f4f4e1e8b9407be728e11af42b7e0f634e
  • devel default
  • master
  • fo
  • jirka/typing
  • fo-base
  • mj/submit-images
  • jk/issue-96
  • jk/issue-196
  • honza/add-contestant
  • honza/mr7
  • honza/mrf
  • honza/mrd
  • honza/mra
  • honza/mr6
  • honza/submit-images
  • honza/kolo-vs-soutez
  • jh-stress-test-wip
  • shorten-schools
19 results

upgrade-20210924.sql

Blame
  • upgrade-20210924.sql 607 B
    SET ROLE 'mo_osmo';
    
    CREATE VIEW region_descendants AS
    	WITH RECURSIVE descendant_regions(place_id, descendant) AS (
    		SELECT place_id, place_id FROM places WHERE level BETWEEN 1 AND 2
    		UNION SELECT r.place_id, p.place_id
    		      FROM descendant_regions r, places p
    		      WHERE p.parent = r.descendant
    	) SELECT place_id AS region, descendant FROM descendant_regions;
    
    CREATE VIEW region_stats AS
    	SELECT c.round_id, rd.region, p.state, count(*)
    	FROM participations p
    	JOIN contests c USING(contest_id)
    	JOIN region_descendants rd ON rd.descendant = c.place_id
    	GROUP BY c.round_id, rd.region, p.state;