ERLEDIGT
NEIN
NEIN
ANTWORTEN
7
7
ZUGRIFFE
639
639
EMPFEHLEN
-
Hi also ich frage mich grade ob es eine Möglichkeit gibt, eine MySQL Ausgabe nach dem letzten Wort eines Strings in einer Spalte zu sortieren oder ob ich da den Umweg über PHP gehen muss ?
Also die Frage ist, kann ich diret über ein spezielles MySQL Query erreichen, dass die Ausgabe nach dem letzten Wort eines Strings in einer Spalte sortiert wird.
Irgendwie doppelt gemoppelt da oben, aber hält ja bekantlich besser
-
Auszug aus mysql.com:
This function is multi-byte safe.
SUBSTRING_INDEX(str,delim,count)
Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned:
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'
mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2);
-> 'mysql.com'
als delimiter ein Leerschlag und du hast das letzte Wort!
Debuggers don't remove Bugs, they only show them in Slow-Motion.
If you can't make it good, at least make it looks good. (Bill Gates)
-
Mmm naja ich kapier das nicht so ganz erhlich gesagt. Also ich habe einen Namen mit mehreren Titeln vorne vor. Die Anzahl dieser kann allerdings variieren. Wie muss nun das ORDER BY SUBSTRING_INDEX aussehen, damit er nach dem letzten Wort (Nachnamen) aus der Spalte name sortiert ?
-
SELECT SUBSTRING_INDEX(testfield, ' ', -1) AS letztes_wort FROM tabelle1 GROUP BY letztes_wort;
etwa so?
Debuggers don't remove Bugs, they only show them in Slow-Motion.
If you can't make it good, at least make it looks good. (Bill Gates)
-
Also ich brauche schon ein SELECT * bzw ein paar Felder. Das macht mich alles ein wenig konfus

//edit: Ah seh schon, kann ich einfach mit Komma getrennt vorran stellen, was ich noch brauche.Geändert von Tim C. (29.09.03 um 15:00 Uhr)
-
ja und? wo ist nun das Problem? wenn du noch andere Felder willst, schreib die doch rein...
SELECT feld1, feld2, feld3, SUBSTRING_INDEX(testfield, ' ', -1) AS letztes_wort FROM tabelle1 GROUP BY letztes_wort;
kannst auch den * reinschreiben... dann hast du halt alle + den substring. ist aber nicht zu empfehlen!
Debuggers don't remove Bugs, they only show them in Slow-Motion.
If you can't make it good, at least make it looks good. (Bill Gates)
-
Siehe mein Edit

Danke nochmals. Hast mir sehr geholfen und mir einen umständlichen Workaround erspart.
-
bidde bidde
Debuggers don't remove Bugs, they only show them in Slow-Motion.
If you can't make it good, at least make it looks good. (Bill Gates)
Ähnliche Themen
-
MySQL Order By Problem
Von as333 im Forum PHPAntworten: 8Letzter Beitrag: 14.08.09, 20:00 -
Dringendes komplexes Problem
Von Tinoh im Forum PHPAntworten: 2Letzter Beitrag: 27.07.07, 22:08 -
[HTMLDB - PL/SQL] komplexes problem
Von SchwarzerMond im Forum Relationale DatenbanksystemeAntworten: 7Letzter Beitrag: 04.05.05, 12:22 -
komplexes JTable Renderer Problem
Von McSnoop im Forum Swing, Java2D/3D, SWT, JFaceAntworten: 11Letzter Beitrag: 11.02.05, 17:32 -
Problem mit mysql Abfrage (Falsche Sorierung (ORDER by))
Von BenoX im Forum PHPAntworten: 4Letzter Beitrag: 10.11.04, 16:45





Zitieren
Login





