1

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
1
  • Thanks solved by valex! Commented May 23, 2014 at 9:07

2 Answers 2

1

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 ;
Sign up to request clarification or add additional context in comments.

1 Comment

WHERE is used to choose which individual rows to use from the table(s) before processong them. HAVING is evaluated after grouping.
1

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 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.