Whats wrong with this SQL Query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thomasjonesmona
    New Member
    • May 2010
    • 3

    Whats wrong with this SQL Query?

    Error message is Msg 130, Level 15, State 1, Line 1
    Cannot perform an aggregate function on an expression containing an aggregate or a subquery.

    Code:
    SELECT     Film.FilmTitle, Person.FirstName
    FROM         Person INNER JOIN
                          Role ON Person.PersonID = Role.PersonID INNER JOIN
                          Film ON Role.FilmID = Film.FilmID
    WHERE Film.FilmID IN 
    (
    SELECT FilmID 
    FROM 
    Award  
    JOIN Role  ON Award.RoleID = Role.RoleID)
    AND Film.FilmID = Role.FilmID
    AND Role.PersonID = Person.PersonID 
    AND Role.PersonID IN
    (SELECT     Role.PersonID
    FROM         Person INNER JOIN
                          Role ON Person.PersonID = Role.PersonID INNER JOIN
                          Award ON Role.RoleID = Award.RoleID
    GROUP BY Role.PersonID
    HAVING COUNT(*) =
    (
    
       SELECT MAX(COUNT(*) )
             FROM     Award INNER JOIN
                 Role ON Award.RoleID = Role.RoleID)
    )
    Last edited by Atli; May 16 '10, 11:57 PM. Reason: Added [code] tags.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    This part is your problem

    Code:
    HAVING COUNT(*) =
    (
      
       SELECT MAX(COUNT(*) )
             FROM     Award INNER JOIN
                 Role ON Award.RoleID = Role.RoleID)
    )
    Happy Coding!!!

    ~~ CK

    Comment

    Working...