1

Ive got the follow sql which counts how many actors have more than 1 role based on actorID

SELECT COUNT (actorID) 
from ROLE
GROUP BY actorID
HAVING COUNT (actorID) > 3;

It gives me the followin result which is correct

COUNT(ACTORID)
         4
         5
         4
         4

However I WANT it to give me the total of 4 (4 actors have more than 3 film roles)

2 Answers 2

2

You have to do this in two steps.

First, identify the actors with more than 3 films, as you have done. Then count those records in a separate query...

SELECT
  COUNT(*)
FROM
(
  SELECT   actorID
  FROM     ROLE
  GROUP BY actorID
  HAVING   COUNT(*) > 3
)
  AS actors
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! It didnt like the As Actors at the end but other worked! perfect!
0

Try substituting HAVING for WHERE

1 Comment

@LillyPop - If you correct your answer, people will remove their -1's. But as it stands your answer suggests trying something syntactically impossible. Because it's a completely incorrect answer, it gets -1 to signify that. But if you alter your answer to be something at least valid, then you don't get -1.

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.