database: Add v_stat_member

This commit is contained in:
2023-12-22 20:42:47 +01:00
parent 35d313d1ea
commit 4ee780183e
2 changed files with 14 additions and 4 deletions

View File

@ -39,7 +39,7 @@ ORDER BY year;
CREATE VIEW v_stat_sort AS CREATE VIEW v_stat_sort AS
SELECT year, sortid, SELECT year, sortid,
SUM(weight) as sum, SUM(weight) AS sum,
ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw, ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw,
ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe, ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe,
COUNT(DISTINCT did) AS lieferungen, COUNT(DISTINCT did) AS lieferungen,
@ -50,7 +50,7 @@ ORDER BY year, sortid;
CREATE VIEW v_stat_attr AS CREATE VIEW v_stat_attr AS
SELECT year, attrid, SELECT year, attrid,
SUM(weight) as sum, SUM(weight) AS sum,
ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw, ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw,
ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe, ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe,
COUNT(DISTINCT did) AS lieferungen, COUNT(DISTINCT did) AS lieferungen,
@ -61,7 +61,7 @@ ORDER BY year, attrid;
CREATE VIEW v_stat_sort_attr AS CREATE VIEW v_stat_sort_attr AS
SELECT year, sortid, attrid, SELECT year, sortid, attrid,
SUM(weight) as sum, SUM(weight) AS sum,
ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw, ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw,
ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe, ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe,
COUNT(DISTINCT did) AS lieferungen, COUNT(DISTINCT did) AS lieferungen,
@ -70,6 +70,16 @@ FROM v_delivery
GROUP BY year, sortid, attrid GROUP BY year, sortid, attrid
ORDER BY year, sortid, attrid; ORDER BY year, sortid, attrid;
CREATE VIEW v_stat_member AS
SELECT year, mgnr,
SUM(weight) AS sum,
ROUND(SUM(kmw * weight) / SUM(weight), 2) AS kmw,
ROUND(SUM(oe * weight) / SUM(weight), 1) AS oe,
COUNT(DISTINCT did) AS lieferungen
FROM v_delivery
GROUP BY year, mgnr
ORDER BY year, mgnr;
CREATE VIEW v_bki_member AS CREATE VIEW v_bki_member AS
SELECT s.year, m.mgnr, m.lfbis_nr, m.family_name, SELECT s.year, m.mgnr, m.lfbis_nr, m.family_name,
(COALESCE(m.prefix || ' ', '') || m.given_name || COALESCE(' ' || m.middle_names, '') || COALESCE(' ' || m.suffix, '')) AS name, (COALESCE(m.prefix || ' ', '') || m.given_name || COALESCE(' ' || m.middle_names, '') || COALESCE(' ' || m.suffix, '')) AS name,

View File

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