Zitat:
Zitat von y20frank
Wer weiß Rat?
|
Tritt MySQL in die Tonne, es übersieht hier einen Syntaxfehler gemäß der SQL-Spec und liefert Dir auch noch ein falschen Resultat.
Ich stelle das mal vereinfach mit PostgreSQL nach:
Code:
test=*# select * from y20;
id | v1 | v2 | v3 | ts
----+----+----+----+----
1 | 22 | 27 | 23 | 4
2 | 25 | 37 | 21 | 5
3 | 24 | 34 | 23 | 6
4 | 27 | 35 | 22 | 7
5 | 23 | 30 | 21 | 8
(5 rows)
Halt vereinfach, alles int-Werte, auch für den timestamp.
Deine Abfrage in PG wirft einen Fehler:
Code:
test=# select greatest(max(v1), max(v2), max(v3)) as maxval, ts from y20;
ERROR: column "y20.ts" must appear in the GROUP BY clause or be used in an aggregate function at character 55
STATEMENT: select greatest(max(v1), max(v2), max(v3)) as maxval, ts from y20;
ERROR: column "y20.ts" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: ...ct greatest(max(v1), max(v2), max(v3)) as maxval, ts from y2...
Da weiß man gleich, was los ist, oder?
Code:
test=*# select greatest(max(v1), max(v2), max(v3)) as maxval, ts from y20 group by ts order by maxval desc limit 1;
maxval | ts
--------+----
37 | 5
(1 row)