Einzelnen Beitrag anzeigen

Blup

Registriert seit: 7. Aug 2008
Ort: Brandenburg
1.429 Beiträge
 
Delphi 10.4 Sydney
 
#7

AW: Komplizierte Mysql-Abfrage

  Alt 21. Mär 2014, 14:58
Mit einem kleine Sript geht es vieleicht, mal so aus dem Stand:
Code:
ALTER TABLE T_ARTIKEL ADD TEMP INTEGER;

update tabelle a
set   a.temp = (select sum(b.rueckstand) from tabelle b where (b.artikel_id = a.artikel_id))
               -(select sum(c.anzahl)    from tabelle c where (c.artikel_id = a.artikel_id) and (c.archiv_id < a.archiv_id));

update tabelle
set   anzahl = 0,
       temp  = 0
where (temp > anzahl);

update tabelle
set   anzahl = anzahl - temp,
       temp  = 0
where (temp > 0);
  Mit Zitat antworten Zitat