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????
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????
Please also mark the comments that contributed to the solution of the article
Content-Key: 73692
Url: https://administrator.de/contentid/73692
Printed on: April 23, 2024 at 20:04 o'clock
1 Comment
Moin christianwes,
Gegenfrage: gibt es einen Grund dafür, warum das Datenbanksystem für nicht nennenswert hältst?
Gruß
Biber
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