Ich habe 2 Tabellen, die Status-Tabelle mit Profil-Tabelle verbunden sind. Die eindeutige tagId und die Statustabelle des Profiltabellenspeichers speichern mehrere doppelte tagid-Einträge. Ich möchte die Gruppe nach Tagids letztem Datensatz und dem ersten Datensatz zeigen.Mysql Query Group nach letzten Datensatz und ersten Datensatz
Tabelle: Hinweis Profil: TagId ist einzigartig
--------------------------------------------------------------------
| tagId(PK) | blah2 | blah3 | blah4 |
--------------------------------------------------------------------
101 |
102 |
103 |
104 |
105 |
106 |
Tabelle: Status
--------------------------------------------------------------------
statusId | tagId | date | height| weight | statusType | blah2 |
--------------------------------------------------------------------
1 | 101 | 2010-01-01 | 5.6 | 300 | single |
2 | 102 | 2010-01-01 | 5.7 | 300 | single |
3 | 101 | 2015-01-01 | 5.6 | 310 | married |
4 | 103 | 2010-01-01 | 5.6 | 300 | single |
5 | 104 | 2010-01-01 | 5.6 | 300 | single |
6 | 101 | 2016-01-01 | 5.6 | 300 | pregnant |
7 | 101 | 2016-09-01 | 5.6 | 300 | delivery |
8 | 105 | 2010-01-01 | 5.6 | 300 | single |
Was ich zuerst Datum und Gruppe von im letzten Statustype
Ergebnis der Abfrage, um zu versuchen Gruppe wollen wird sein:
--------------------------------------------------------------------
| tagId | date | height| weight | statusType | blah2 |
--------------------------------------------------------------------
| 101 | 2010-01-01 | 5.6 | 300 | delivery |
| 102 | 2010-01-01 | 5.7 | 300 | single |
| 103 | 2010-01-01 | 5.6 | 300 | single |
| 104 | 2010-01-01 | 5.6 | 300 | single |
| 105 | 2010-01-01 | 5.6 | 300 | single |
Aber ich kann nicht mit ihm Erfolg, habe ich versucht, mit diesem MySQL-Code
SELECT DISTINCT Profile.TagId,Status.date,Status.StatusType,Status.height,Status.weight FROM Profile
LEFT JOIN Status ON Status.TagId = Profile.TagId
Where Status.StatusId In(Select Max(Status.StatusId) From Status Group By Status.TagId)
Group By Status.TagId ORDER BY Profile.TagId ASC, Status.TagId DESC
Aber es gibt letztes Datum und die letzte Statustype, wie dieses
Abfrage Ergebnis:
--------------------------------------------------------------------
| tagId | date | height| weight | statusType | blah2 |
--------------------------------------------------------------------
| 101 | 2016-09-01 | 5.6 | 300 | delivery |
| 102 | 2010-01-01 | 5.7 | 300 | single |
| 103 | 2010-01-01 | 5.6 | 300 | single |
| 104 | 2010-01-01 | 5.6 | 300 | single |
| 105 | 2010-01-01 | 5.6 | 300 | single |
Was ist "Höhe" und "Gewicht"? – Blank
Höhe vergessen, Gewicht @Reno –
Ich verstehe es einfach nicht, aber vielleicht war es leichter zu verstehen, bevor – Strawberry