MySql-Query: Wie kann man die Summe der having-Summe ausgeben...

select coalesce(kategorie,'GESAMTSUMME'), sum(brutto) total from billing.ausgaben group by rollup(kategorie) order by total;

Also da kommt bei mir ein Fehler:

SQL-Fehler [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(kategorie) order by total
LIMIT 0, 200' at line 1
 
Werbung:
Das coalesce kennt mysql schon:

SELECT coalesce(kategorie), sum(brutto) from billing.ausgaben where substr(datum,1,4) = 2020 group by kategorie order by sum(brutto) DESC ;

Da kommt schon was Richtiges raus, nur fehlt hier - ganz unten -die Gesamtsumme.

Miete/HLG-3 7321.04
Lebensmittel 6550.10
Wellness 1467.40
Medizin 1169.88

Nur das group by rollup(kategrorie) muss man anscheinend anders schreiben.
 
Werbung:
Also, so funktioniert es jetzt:
SELECT coalesce(kategorie, 'GESAMT'), sum(brutto) from billing.ausgaben where substr(datum,1,4) = 2020 group by kategorie with ROLLUP order by sum(brutto) DESC; (oder ASC)

Und das Datum ist in der mysql-DB schon als Datum eingetragen:
datum date YES

Nur für Java ist das egal. Java kann ganz einfach das Datum in String konvertieren - ohne Konvertierungs-Anweisung.
Danke nochmals für die Hilfe :)
 
Zurück
Oben