MySQL Forums
Forum List  »  German

vorherige Summe in die laufende Zeile übertragen
Posted by: alain dudikopf
Date: April 10, 2012 09:06AM

Hallo Zusammen,
ich möchte eine Abfrage schreiben, die mir für eine gegebene Zeile sowohl die aktuelle Summe (anz_ges) als auch die Summe des Vortages (anz_ges_vt) ausgibt.
Ich habe es so probiert, aber es klappt leider nicht:

SELECT datum, count(if(knz=0, pNr, null)) as anz1, count(if(knz=1, pNr, null)) as anz2, count(distinct pNr) as anz_ges, count(if(datum=ADDDATE(datum, -1),1,null)) as anz_ges_vt FROM tabelle1 t1 where state=100 and pNr not in (select pNr from tabelle1 where state=200) group by datum;

erwünschte Ausgabe:
datum-- anz1-- anz2-- anz_ges-- anz_ges_vt
02.04.2012-- 12-- 13-- 25-- 0
03.04.2012-- 4-- 7-- 11-- 25
04.04.2012-- 22-- 5-- 27-- 11
05.04.2012-- 10-- 30-- 40-- 27
10.04.2012-- 9-- 6-- 15-- 40
kann mir irgendjemand behilflich sein?
Danke!

Michael

Options: ReplyQuote


Subject
Views
Written By
Posted
vorherige Summe in die laufende Zeile übertragen
3732
April 10, 2012 09:06AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.