christianwes

SQL wie union ergebnisse summieren?

Hi Leute!

habe eine abfrage mit:

select Jahr, Monat, sum(anzahl*preis) as Umsatz

from rechnungen

where article_id is not null

group by Jahr, Monat

union

select Jahr, Monat, sum(anzahl*preis) as Umsatz

from aio_rechnugen

where d.description is not null

group by Jahr, Monat

order by Jahr desc, Monat desc;



Jetzt bekomme ich aber 2 Ergebnisse pro Monat und möchte diese wieder summieren, so funktionierts bei mir aber nicht:

select Jahr, Monat, sum(Umsatz) from (

select Jahr, Monat, sum(anzahl*preis) as Umsatz

from rechnungen

where article_id is not null

union

select Jahr, Monat, sum(anzahl*preis) as Umsatz

from aio_rechnugen

where d.description is not null

)

group by Jahr, Monat

order by Jahr desc, Monat desc;


Hat jemand von euch eine Idee dazu????
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 73692

Url: https://administrator.de/forum/sql-wie-union-ergebnisse-summieren-73692.html

Ausgedruckt am: 10.05.2025 um 18:05 Uhr

Biber
Biber 16.11.2007 um 12:37:37 Uhr
Goto Top
Moin christianwes,

Gegenfrage: gibt es einen Grund dafür, warum das Datenbanksystem für nicht nennenswert hältst?

 select all.* from (
select Jahr, Monat, sum(Umsatz) from (

select Jahr, Monat, sum(anzahl*preis) as Umsatz 

from rechnungen

where article_id is not null

union

select Jahr, Monat, sum(anzahl*preis) as Umsatz 

from aio_rechnugen 

where d.description is not null

) all

group by Jahr, Monat

order by Jahr desc, Monat desc; 

Gruß
Biber