ich in meiner DB nächste Tabelle habe:MySQL Wie smth von MAX wählen (id) .... WHERE userID = eine Zahl GROUP BY smth
personal_prizes
___________ ___________ _________ __________
| id | userId | specId| grp |
|___________|___________|_________|__________|
| 1 | 1 | 1 | 1 |
| 2 | 1 | 2 | 1 |
| 3 | 2 | 3 | 1 |
| 4 | 2 | 4 | 2 |
| 5 | 1 | 5 | 2 |
| 6 | 1 | 6 | 2 |
| 7 | 2 | 7 | 3 |
| 8 | 1 | 13 | 4 |
|___________|___________|_________|__________|
I specId auswählen muß von max id group von grp. So habe ich komponiert nächste Abfrage
SELECT pp.specId
FROM personal_prizes pp
WHERE pp.specId IN (SELECT MAX(pp1.id)
FROM personal_prizes pp1
WHERE pp1.userId = 1
GROUP BY pp1.grp)
Und es ist Arbeit für meinen kleinen Tisch. Aber wenn ich versuche, es für meine prod db mit personal_prices> 100.000 zu implementieren. Bitte helfen Sie mir, es zu optimieren
Wir könnten versuchen, Ihre Abfrage neu zu schreiben, aber mit nur 100K Datensätze ist die Leistung wirklich ein Problem für Sie? –
Oh ... Gibt es noch ein anderes Problem? –
Es gibt kein Problem. – trincot