Query failed (aggregate function or the GROUP BY clause)

  • SAMPLE QUERY :

    SELECT name, SUM(population)

    FROM bbc

    where population >1000

    query failed and got error msg 8120

    ERROR

    "Column 'tt.dbo.bbc.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."

    I want to select name and corresponding sum (population) ..

    help???

  • If your using an aggregate function in the select, you need to put in a group by clause of all the columns which are not encased in an aggregate

    SELECT name, SUM(population)

    FROM bbc

    WHERE population >1000

    GROUP BY name

  • SELECT name as Name, SUM(population) as Popualtion

    FROM bbc

    WHERE population >1000

    GROUP BY name

    If you aggregate the specific column then other remaining column in the select list should be group by...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply