MySQL Forums
Forum List  »  German

Group by Frage
Posted by: michael skibb
Date: June 28, 2009 03:35PM

Hallo Allerseits,
ich habe folgendes Problem. In einer Tabelle sind für verschiedenste Produkte zeitbezogen verschiedene Preise hinterlegt:
id unique_id produkt_verpackungen_id markt_id preis created_at user
1 1 1 6 5.99 2009-06-28 11:08:09 NULL
2 2 1 3 10 2009-06-28 12:04:29 NULL
3 2 1 3 11 2009-06-28 12:05:59 NULL
4 1 1 6 6.01 2008-06-28 12:09:12 NULL
5 1 1 6 5.99 2008-06-28 12:09:44 NULL
6 6 1 3 12 2009-06-28 12:09:44 NULL
7 7 2 3 4.05 2009-06-28 14:12:52 NULL
8 8 2 6 3.99 2009-06-28 14:12:52 NULL
9 8 2 6 4 2008-06-28 14:13:24 NULL
Nun möchte ich in einem statement für alle Produkte (bzw. Produkt_Verpackungen) den aktuellesten Preis holen, gruppiert nach märkten und den produkten
Dazu verwendete ich group_by wie folgt:
select preis, produkt_verpackungen_id, markt_id, max(created_at) as maximum from produkt_markt_preis group by markt_id, produkt_verpackungen_id
allerdings erhalte ich damit nicht den preis zum datum (maximum). erwartet hätte ich bspw. für das produkt mit der produkt_verpackungen_id = 1 und der markt_id = 3 als datum (maximum) = '2009-06-28 12:09:44' und als preis = 12. allerdings erhalte ich als preis = 10.
weiss jemand, woran das liegt bzw. wie man die gewünschte abhängigkeit in ein statement giessen kann? danke im voraus,
roelfsche

Options: ReplyQuote


Subject
Views
Written By
Posted
Group by Frage
2660
June 28, 2009 03:35PM


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.