Translations:Faq/Base/142/7/de

From The Document Foundation Wiki
Jump to: navigation, search

Hier ist der Betrag in die Summe aus den bisherigen Monaten und den Betrag des aktuellen Monats aufgesplittet.

SELECT DISTINCT 'Summe',
(SELECT SUM("Betrag") FROM "Einkauf" WHERE EXTRACT(MONTH FROM "Datum") < EXTRACT(MONTH FROM CURRENT_DATE) OR EXTRACT(YEAR FROM "Datum") < EXTRACT(YEAR FROM CURRENT_DATE)) AS "Saldo Vormonat",
(SELECT SUM("Betrag") FROM "Einkauf" WHERE EXTRACT(MONTH FROM "Datum") = EXTRACT(MONTH FROM CURRENT_DATE) AND EXTRACT(YEAR FROM "Datum") = EXTRACT(YEAR FROM CURRENT_DATE)) AS "aktueller Monat",
(SELECT SUM("Betrag") FROM "Einkauf") AS "Saldo" FROM "Kategorie"
Diese 2. Abfrage ermittelt nur die Summen ohne Berücksichtigung der Kategorien. Die beiden Abfragen werden mit UNION verbunden. Allerdings muss vorher in den direkten SQL-Modus umgestellt werden. Abfragen, die mit UNION verbunden werden funktionieren nicht in der GUI. SELECT "a"."Kategorie",
(SELECT SUM("Betrag") FROM "Einkauf" WHERE "KategorieID" = "a"."ID" AND (EXTRACT(MONTH FROM "Datum") < EXTRACT(MONTH FROM CURRENT_DATE) OR EXTRACT(YEAR FROM "Datum") < EXTRACT(YEAR FROM CURRENT_DATE))) AS "Saldo Vormonat",
(SELECT SUM("Betrag") FROM "Einkauf" WHERE "KategorieID" = "a"."ID" AND (EXTRACT(MONTH FROM "Datum") = EXTRACT(MONTH FROM CURRENT_DATE) AND EXTRACT(YEAR FROM "Datum") = EXTRACT(YEAR FROM CURRENT_DATE))) AS "aktueller Monat",
(SELECT SUM("Betrag") FROM "Einkauf" WHERE "KategorieID" = "a"."ID") AS "Saldo" FROM "Kategorie" AS "a"
UNION
SELECT DISTINCT 'Summe',
(SELECT SUM("Betrag") FROM "Einkauf" WHERE EXTRACT(MONTH FROM "Datum") < EXTRACT(MONTH FROM CURRENT_DATE) OR EXTRACT(YEAR FROM "Datum") < EXTRACT(YEAR FROM CURRENT_DATE)) AS "Saldo Vormonat",
(SELECT SUM("Betrag") FROM "Einkauf" WHERE EXTRACT(MONTH FROM "Datum") = EXTRACT(MONTH FROM CURRENT_DATE) AND EXTRACT(YEAR FROM "Datum") = EXTRACT(YEAR FROM CURRENT_DATE)) AS "aktueller Monat",
(SELECT SUM("Betrag") FROM "Einkauf") AS "Saldo" FROM "Kategorie"