database: Add v_stat_total

This commit is contained in:
2024-04-30 23:33:39 +02:00
parent a047997fc1
commit b0db769042
2 changed files with 17 additions and 1 deletions

View File

@ -131,3 +131,19 @@ SELECT s.year, m.mgnr, m.business_shares,
FROM member m, season s
LEFT JOIN v_stat_member d ON (d.year, d.mgnr) = (s.year, m.mgnr)
ORDER BY s.year, m.mgnr;
CREATE VIEW v_stat_total AS
SELECT d.year, d.zwstid, v.type, v.sortid,
IIF(b.discr = a.attrid OR NOT a.area_com, a.attrid, NULL) AS attrid,
p.cultid, q.qualid,
IIF(b.discr = '_', 'ungeb', 'geb') AS geb,
SUM(value) AS weight
FROM delivery_part p
LEFT JOIN delivery d ON (d.year, d.did) = (p.year, p.did)
LEFT JOIN wine_variety v ON v.sortid = p.sortid
LEFT JOIN wine_quality_level q ON q.qualid = p.qualid
LEFT JOIN delivery_part_bucket b ON (b.year, b.did, b.dpnr) = (p.year, p.did, p.dpnr)
LEFT JOIN v_wine_attribute a ON a.attrid = p.attrid
GROUP BY d.year, d.zwstid, v.type, v.sortid, IIF(b.discr = a.attrid OR NOT a.area_com, a.attrid, NULL), p.cultid, q.qualid, geb
HAVING SUM(value) > 0
ORDER BY d.year, d.zwstid, v.type DESC, v.sortid, IIF(b.discr = a.attrid OR NOT a.area_com, a.attrid, NULL), p.cultid, q.min_kmw, geb;

View File

@ -1,3 +1,3 @@
-- This value MUST NOT be changed while other connections are open!
PRAGMA schema_version = 1800;
PRAGMA schema_version = 1900;