Invalid Group function

From SQLZOO
Revision as of 12:20, 19 July 2012 by Marek (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
schema:gisq
Msg 1013, Ambiguous column name 'name'.

Problem

We want to filter the results returned based on an aggregate function such as COUNT or SUM.

The WHERE clause may not be used for this. The WHERE conditions are considered before the aggregation.

Solutions

  • Put the condition into the HAVING clause, after the GROUP BY clause.
  • SELECT winner FROM nobel
      GROUP BY winner
      HAVING COUNT(winner)>1
    
 
 
SELECT winner FROM nobel
 WHERE COUNT(winner)>1
GROUP BY winner
Personal tools
Namespaces

Variants
Actions
Reference
Toolbox
Google AdSense