thechinese
thechinese

Reputation: 57

SQL DB2 query error

I'm trying to get a hang on SQL, but I dont know why this doesn't work.

    SELECT p.Ort, COUNT(Projekt.Ort) AS Anzahl
    FROM Projekt p
    WHERE Anzahl > 2 GROUP BY p.Ort;

If I try to use this I get:

    "ANZAHL" is not valid in the context where it is used.. SQLCODE=-206, SQLSTATE=42703, DRIVER=4.9.78

Upvotes: 1

Views: 243

Answers (2)

valex
valex

Reputation: 24144

You should HAVING instead of WHERE

  SELECT p.Projektort, COUNT(Projekt.Projektort) AS ProjektAnzahl
  FROM Projekt p
  GROUP BY p.Projektort
  HAVING COUNT(Projekt.Projektort) > 2 ;

Upvotes: 1

Josh
Josh

Reputation: 8016

In GROUP BY clauses, the HAVING keyword is used:

SELECT p.Projektort, COUNT(Projekt.Projektort) AS ProjektAnzahl
FROM Projekt p
GROUP BY p.Projekt
HAVING ProjektAnzahl > 2 

Upvotes: 1

Related Questions