MySQL: Ungültige Verwendung der Gruppenfunktion
Ich benutze MySQL. Hier ist mein Schema:
Lieferanten(sid: Ganzzahl, Sname: String, Adressstring)
Teile(pid: Ganzzahl, pname: string, farbe: string)
Katalog(sid: Ganzzahl, pid: Ganzzahl, Kosten: real)
(Primärschlüssel sind fett gedruckt)
Ich versuche eine Anfrage zu schreiben, um alle Teile auszuwählen, die von mindestens zwei Lieferanten hergestellt werden:
-- Find the pids of parts supplied by at least two different suppliers.
SELECT c1.pid -- select the pid
FROM Catalog AS c1 -- from the Catalog table
WHERE c1.pid IN ( -- where that pid is in the set:
SELECT c2.pid -- of pids
FROM Catalog AS c2 -- from catalog
WHERE c2.pid = c1.pid AND COUNT(c2.sid) >= 2 -- where there are at least two corresponding sids
);
Zuallererst, gehe ich das überhaupt richtig an?
Zweitens bekomme ich diesen Fehler:
1111 - Ungültige Verwendung der Gruppenfunktion
Was mache ich falsch?