mySQL: Satz mit dem minimalen Wert
bearbeitet von Rolf BHallo Linuchs,
sicher?
Angenommene Datenbasis:
~~~
Col1 Col2 Col3 Col4
A 2 A23 A24
A 1 A13 A14
B 3 B33 B34
B 2 B23 B24
~~~
Darauf wenden wir an:
~~~sql
SELECT Col1, MIN(Col2) As Min2, Col3, Col4
FROM table
GROUP BY Col1
~~~
Ergebnis kann sein:
~~~
Col1 Min2 Col3 Col4
A 1 A23 A24
B 2 A33 A34
~~~
Warum: Für Min2 hast Du eine Aggregatfunktion und bekommst das Minimum über der Col1-Gruppe. Für Col3 und Col4 hast Du keine Aggregatfunktion und bekommst irgendeinen Wert aus der Col1-Gruppe - aber NICHT irgendeinen Wert aus einer Zeile mit einem Minimum.
Ich habe das gerade einmal mit MYSQL 5.6 ausprobiert, genau so scheint's zu passieren.
_Rolf_
--
sumpsi - posui - clusi
mySQL: Satz mit dem minimalen Wert
bearbeitet von Rolf BHallo Linuchs,
sicher?
Angenommene Datenbasis:
~~~
Col1 Col2 Col3 Col4
A 2 A23 A24
A 1 A13 A14
B 3 B33 B34
B 2 B23 B24
~~~
Darauf wenden wir an:
~~~sql
SELECT Col1, MIN(Col2) As Min2, Col3, Col4
FROM table
GROUP BY Col1
~~~
Ergebnis kann sein:
~~~
Col1 Min2 Col3 Col4
A 1 A23 A24
B 2 A33 A34
~~~
Warum: Für Min2 hast Du eine Aggregatfunktion und bekommst das Minimum über der Col1-Gruppe. Für Col3 und Col4 hast Du keine Aggregatfunktion und bekommst irgendeinen Wert aus der Col1-Gruppe - aber NICHT irgendeinen Wert aus einer Zeile mit einem Minimum.
Vielleicht habe ich ja diese MYSQL-Erweiterung falsch verstanden, aber nach meiner Auffassung droht Dir genau dieses Problem.
_Rolf_
--
sumpsi - posui - clusi