Do not use bio as attribute
This commit is contained in:
@ -61,7 +61,7 @@ CREATE TABLE area_commitment_type (
|
||||
) STRICT;
|
||||
|
||||
CREATE TABLE wine_cultivation (
|
||||
cultid TEXT NOT NULL CHECK (cultid REGEXP '^[A-Z]+$'),
|
||||
cultid TEXT NOT NULL CHECK (cultid REGEXP '^[A-Z][A-Z0-9]*$'),
|
||||
name TEXT NOT NULL,
|
||||
description TEXT DEFAULT NULL,
|
||||
|
||||
@ -175,7 +175,7 @@ CREATE TABLE area_commitment (
|
||||
mgnr INTEGER NOT NULL,
|
||||
|
||||
vtrgid TEXT NOT NULL,
|
||||
cultid TEXT NOT NULL,
|
||||
cultid TEXT DEFAULT NULL,
|
||||
area INTEGER NOT NULL,
|
||||
|
||||
kgnr INTEGER NOT NULL,
|
||||
|
@ -89,7 +89,8 @@ CREATE TABLE delivery_part (
|
||||
dpnr INTEGER NOT NULL,
|
||||
|
||||
sortid TEXT NOT NULL,
|
||||
attrid TEXT,
|
||||
attrid TEXT DEFAULT NULL,
|
||||
cultid TEXT DEFAULT NULL,
|
||||
weight INTEGER NOT NULL,
|
||||
kmw REAL NOT NULL,
|
||||
qualid TEXT NOT NULL,
|
||||
@ -98,7 +99,7 @@ CREATE TABLE delivery_part (
|
||||
kgnr INTEGER DEFAULT NULL,
|
||||
rdnr INTEGER DEFAULT NULL,
|
||||
|
||||
gerebelt INTEGER NOT NULL CHECK (gerebelt IN (TRUE, FALSE)),
|
||||
net_weight INTEGER NOT NULL CHECK (net_weight IN (TRUE, FALSE)),
|
||||
manual_weighing INTEGER NOT NULL CHECK (manual_weighing IN (TRUE, FALSE)),
|
||||
spl_check INTEGER NOT NULL CHECK (spl_check IN (TRUE, FALSE)) DEFAULT FALSE,
|
||||
|
||||
@ -127,6 +128,9 @@ CREATE TABLE delivery_part (
|
||||
CONSTRAINT fk_delivery_part_wine_attribute FOREIGN KEY (attrid) REFERENCES wine_attribute (attrid)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_delivery_part_wine_cultivation FOREIGN KEY (cultid) REFERENCES wine_cultivation (cultid)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE RESTRICT,
|
||||
CONSTRAINT fk_delivery_part_wine_quality_level FOREIGN KEY (qualid) REFERENCES wine_quality_level (qualid)
|
||||
ON UPDATE CASCADE
|
||||
ON DELETE RESTRICT,
|
||||
|
@ -11,14 +11,21 @@ FROM season
|
||||
UNION
|
||||
SELECT strftime('%Y', date()) + 0, (SELECT max_kg_per_ha FROM season ORDER BY year DESC LIMIT 1);
|
||||
|
||||
CREATE VIEW v_wine_attribute AS
|
||||
SELECT a.attrid, name, active, max_kg_per_ha, strict, fill_lower,
|
||||
COUNT(t.attrid) > 0 AS area_com
|
||||
FROM wine_attribute a
|
||||
LEFT JOIN area_commitment_type t ON t.attrid = a.attrid
|
||||
GROUP BY a.attrid;
|
||||
|
||||
CREATE VIEW v_delivery AS
|
||||
SELECT p.year, p.did, p.dpnr,
|
||||
d.date, d.time, d.zwstid, d.lnr, d.lsnr,
|
||||
m.mgnr, m.family_name, m.given_name,
|
||||
p.sortid, a.attrid,
|
||||
p.sortid, a.attrid, p.cultid,
|
||||
p.weight, p.kmw, ROUND(p.kmw * (4.54 + 0.022 * p.kmw), 0) AS oe, p.qualid,
|
||||
p.hkid, p.kgnr, p.rdnr,
|
||||
p.gerebelt, p.gebunden,
|
||||
p.net_weight, p.gebunden,
|
||||
p.qualid IN (SELECT l.qualid FROM wine_quality_level l WHERE NOT l.predicate AND (p.kmw >= l.min_kmw OR l.min_kmw IS NULL) ORDER BY l.min_kmw DESC LIMIT 1,100) AS abgewertet,
|
||||
p.qualid NOT IN ('WEI', 'RSW', 'LDW') AS min_quw,
|
||||
IIF(a.strict, COALESCE(a.fill_lower, 0), 0) AS attribute_prio,
|
||||
|
@ -33,24 +33,25 @@ ORDER BY year, mgnr, bucket;
|
||||
|
||||
CREATE VIEW v_delivery_bucket_strict AS
|
||||
SELECT year, mgnr,
|
||||
sortid || IIF(min_quw, COALESCE(attrid, ''), '_') AS bucket,
|
||||
sortid, IIF(min_quw, attrid, NULL) AS attrid,
|
||||
sortid || IIF(min_quw OR NOT COALESCE(area_com, TRUE), COALESCE(a.attrid, ''), '_') AS bucket,
|
||||
sortid, IIF(min_quw OR NOT COALESCE(area_com, TRUE), a.attrid, NULL) AS attrid,
|
||||
SUM(weight) AS weight,
|
||||
min_quw
|
||||
FROM v_delivery
|
||||
min_quw OR NOT COALESCE(area_com, TRUE) AS valid
|
||||
FROM v_delivery d
|
||||
LEFT JOIN v_wine_attribute a ON a.attrid = d.attrid
|
||||
GROUP BY year, mgnr, bucket
|
||||
ORDER BY year, mgnr, bucket;
|
||||
|
||||
CREATE VIEW v_delivery_bucket AS
|
||||
SELECT year, mgnr, bucket, weight
|
||||
FROM v_delivery_bucket_strict
|
||||
WHERE attrid IS NOT NULL OR NOT min_quw
|
||||
WHERE attrid IS NOT NULL OR NOT valid
|
||||
UNION ALL
|
||||
SELECT b.year, b.mgnr, b.sortid,
|
||||
SUM(b.weight) AS weight
|
||||
FROM v_delivery_bucket_strict b
|
||||
LEFT JOIN wine_attribute a ON a.attrid = b.attrid
|
||||
WHERE min_quw AND (a.strict IS NULL OR a.strict = FALSE)
|
||||
WHERE valid AND (a.strict IS NULL OR a.strict = FALSE)
|
||||
GROUP BY b.year, b.mgnr, b.sortid
|
||||
ORDER BY year, mgnr, bucket;
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
|
||||
-- This value MUST NOT be changed while other connections are open!
|
||||
PRAGMA schema_version = 1700;
|
||||
PRAGMA schema_version = 1800;
|
||||
|
Reference in New Issue
Block a user