Skip to content
Snippets Groups Projects

Reforma orgovského rozhraní ke kolům a soutěžím

Merged Martin Mareš requested to merge mj/contest-reform into devel
2 files
+ 36
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 20
0
@@ -355,3 +355,23 @@ CREATE TABLE reg_requests (
user_id int DEFAULT NULL REFERENCES users(user_id) ON DELETE CASCADE,
client varchar(255) NOT NULL -- kdo si registraci vyžádal
);
-- Statistiky
-- Pro každý region úrovně <= 2 spočítáme všechna podřízená místa
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;
-- Pro každou trojici (kolo, region, stav účasti) spočítáme účastníky.
-- Pokud se to ukáže být příliš pomalé, přejdeme na materializovaná views.
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;
Loading