-- schema version 11 to 12

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;
