Skip to content
Snippets Groups Projects
Commit 9aa870f4 authored by Martin Mareš's avatar Martin Mareš
Browse files

tmp

parent c480f27b
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !95. Comments created here will be created in the context of that merge request.
......@@ -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;
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;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment