MySQL Forums
Forum List  »  German

MAX von SUM
Posted by: J?rg B?chner
Date: August 04, 2011 06:18AM

Guten Tag,

ich möchte gerne den Maximalwert der Summen aller positiven Werte berechnen
oder anders gefragt: "Wer hat die meisten Pluspunkte?"
In unserem Fall ist das Berta mit 400.
CREATE TABLE tbl (name CHAR(30), wert INT);
INSERT INTO tbl VALUES ('Anton', 300);
INSERT INTO tbl VALUES ('Berta', 200);
INSERT INTO tbl VALUES ('Anton', -200);
INSERT INTO tbl VALUES ('Berta', -100);
INSERT INTO tbl VALUES ('Berta', 200);

Versucht habe ich es mit
SELECT name FROM
 (SELECT name, SUM(wert) AS w FROM tbl WHERE wert>0 GROUP BY name) AS s
HAVING MAX(w)
doch das ist falsch.

Gruß
Jörg

Options: ReplyQuote


Subject
Views
Written By
Posted
MAX von SUM
2047
August 04, 2011 06:18AM
1117
August 04, 2011 08:08AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.