فهرست منبع

MAX in WHERE not possible

You cannot use MAX() in a WHERE clause, instead use a subquery.

The ORDER BY is also unneeded, because we only select the maximum. So what to order, there is only one number (even if multiple entries with the same number).
Stefan Koch 12 سال پیش
والد
کامیت
097d360423
1فایلهای تغییر یافته به همراه1 افزوده شده و 2 حذف شده
  1. 1 2
      documents/musterloesung-db-klausur-b/d3e.sql

+ 1 - 2
documents/musterloesung-db-klausur-b/d3e.sql

@@ -1,5 +1,4 @@
 SELECT berater_id, name, anzahl
     FROM Beratungsanzahl
     JOIN Berater ON Berater.berater_id = Beratungsanzahl.berater_id
-    WHERE anzahl = MAX(anzahl)
-    ORDER BY anzahl DESC
+    WHERE anzahl = (SELECT MAX(anzahl) FROM Beratungsanzahl)