wahrscheinlich nicht die eleganteste Lösung, aber es müßte funktionieren:
PHP-Code:
select a.produkt, (select b.preis
from preistabelle as b
where b.produkt = a.produkt
and b.lfnr in (select max(c.lfnr)
from preistabelle as c
where c.produkt = b.produkt)) as aktueller_preis,
ifnull((select d.preis
from preistabelle as d
where d.produkt = a.produkt
and d.lfnr in (select max(e.lfnr)-1
from preistabelle as e
where e.produkt = d.produkt)), 0) as vorheriger_preis,
(select f.preis
from preistabelle as f
where f.produkt = a.produkt
and f.lfnr in (select max(g.lfnr)
from preistabelle as g
where g.produkt = f.produkt)) -
ifnull((select h.preis
from preistabelle as h
where h.produkt = a.produkt
and h.lfnr in (select max(i.lfnr)-1
from preistabelle as i
where i.produkt = h.produkt)), 0) as differenz
from produkttabelle as a
Bookmarks