Commit bc9dc039 authored by Bjarni Pjetursson's avatar Bjarni Pjetursson
Browse files

Update 13-ugyldig-virksomhedstype-paa-enkeltindvindere.sql

parent aad0604e
......@@ -3,29 +3,30 @@
Titel: enkeltindvindere
Status: prototype
*/
SELECT * FROM (
SELECT kommune AS "Kommune", anlaeg AS "Anlæg", status AS "Status", v95 AS "V95(prioritet)", vt_udfaset AS "Forældet virks.type(prio)", vt_andre AS "Andre Virks.typer(prio)" FROM (
SELECT vt.*,
CASE
WHEN ("FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)" LIKE '%V04%' OR "FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)" LIKE '%V05%') AND "V95(PRIORITET)" IS NULL AND "ANDRE VIRKSOMHEDSTYPER(PRIORITET)" IS NULL THEN 'Erstat forældet virksomhedstype med V95 (1 husstand) eller V03 (2-9 husstande)'
WHEN "FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)" LIKE '%M42%' AND ("V95(PRIORITET)" IS NOT NULL OR "ANDRE VIRKSOMHEDSTYPER(PRIORITET)" LIKE '%V03%') THEN 'Uoverensstemmelse mellem den forældede virksomhedstype M42 og andre virksomhedstyper'
WHEN "FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)" LIKE '%M42%' AND ("ANDRE VIRKSOMHEDSTYPER(PRIORITET)" NOT LIKE '%V01%' AND "ANDRE VIRKSOMHEDSTYPER(PRIORITET)" NOT LIKE '%V02%') THEN 'M42 til ??'
WHEN "FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)" LIKE '%M42%' AND "V95(PRIORITET)" IS NULL AND "ANDRE VIRKSOMHEDSTYPER(PRIORITET)" IS NULL THEN 'M42 til ??'
WHEN (("FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)" LIKE '%V04%' OR "FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)" LIKE '%V05%') AND "V95(PRIORITET)" LIKE 'V95%') OR ("V95(PRIORITET)" LIKE 'V95%' AND "ANDRE VIRKSOMHEDSTYPER(PRIORITET)" LIKE '%V03%') THEN 'Uafklaret antal husstande'
WHEN (vt_udfaset LIKE '%V04%' OR vt_udfaset LIKE '%V05%') AND v95 IS NULL AND vt_andre IS NULL THEN 'Erstat forældet virksomhedstype med V95 (1 husstand) eller V03 (2-9 husstande)'
WHEN vt_udfaset LIKE '%M42%' AND (v95 IS NOT NULL OR vt_andre LIKE '%V03%') THEN 'Uoverensstemmelse mellem den forældede virksomhedstype M42 og andre virksomhedstyper'
WHEN vt_udfaset LIKE '%M42%' AND (vt_andre NOT LIKE '%V01%' AND vt_andre NOT LIKE '%V02%') THEN 'M42 til ??'
WHEN vt_udfaset LIKE '%M42%' AND v95 IS NULL AND vt_andre IS NULL THEN 'M42 til ??'
WHEN ((vt_udfaset LIKE '%V04%' OR vt_udfaset LIKE '%V05%') AND v95 LIKE 'V95%') OR (v95 LIKE 'V95%' AND vt_andre LIKE '%V03%') THEN 'Uafklaret antal husstande'
END kontrol
FROM (
SELECT p.municipalityno2007 kommunenr,
m.name kommunenavn,
SELECT
m.name kommune,
p.plantid||' - '||p.plantname AS anlaeg,
st.longtext status,
(SELECT LISTAGG(companytype||'('||companytypeno||')', ',') WITHIN GROUP (ORDER BY companytypeno) FROM drwplantcompanytype WHERE p.plantid = plantid AND companytype IN ('V95') GROUP BY plantid) "V95(PRIORITET)",
(SELECT LISTAGG(companytype||'('||companytypeno||')', ',') WITHIN GROUP (ORDER BY companytypeno) FROM drwplantcompanytype WHERE p.plantid = plantid AND companytype IN ('M42','V04','V05','V06','V07') GROUP BY plantid) "FORÆLDET VIRKSOMHEDSTYPE(PRIORITET)",
(SELECT LISTAGG(companytype||'('||companytypeno||')', ',') WITHIN GROUP (ORDER BY companytypeno) FROM drwplantcompanytype WHERE p.plantid = plantid AND companytype NOT IN ('V95','M42','V04','V05','V06','V07') GROUP BY plantid) "ANDRE VIRKSOMHEDSTYPER(PRIORITET)"
(SELECT LISTAGG(companytype||'('||companytypeno||')', ',') WITHIN GROUP (ORDER BY companytypeno) FROM drwplantcompanytype WHERE p.plantid = plantid AND companytype IN ('V95') GROUP BY plantid) v95,
(SELECT LISTAGG(companytype||'('||companytypeno||')', ',') WITHIN GROUP (ORDER BY companytypeno) FROM drwplantcompanytype WHERE p.plantid = plantid AND companytype IN ('M42','V04','V05','V06','V07') GROUP BY plantid) vt_udfaset,
(SELECT LISTAGG(companytype||'('||companytypeno||')', ',') WITHIN GROUP (ORDER BY companytypeno) FROM drwplantcompanytype WHERE p.plantid = plantid AND companytype NOT IN ('V95','M42','V04','V05','V06','V07') GROUP BY plantid) vt_andre,
CASE WHEN p.xutm32euref89+p.yutm32euref89>0 THEN 'POINT ('||TRIM(TO_CHAR(ROUND(p.xutm32euref89),'999999999990'))||' '||TRIM(TO_CHAR(ROUND(p.yutm32euref89),'999999999990'))||')' END AS wkt
FROM drwplant p
LEFT JOIN municipality2007 m ON p.municipalityno2007 = m.municipalityno2007
LEFT JOIN code_733 st ON p.active = st.code
WHERE NVL(p.dataowner, 'KO') = 'KO'
--and p.plantid in (175950,153737,160050,51087)
ORDER BY m.name, p.plantid
/* DEUBG: AND p.plantid in (175950,153737,160050,51087) */
) vt
)
WHERE kontrol IS NOT NULL;
ORDER BY kommunenavn, anlaeg
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment