<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;feed=atom&amp;action=history</id>
		<title>Invalid Group function - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;action=history"/>
		<updated>2013-05-24T15:57:31Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;diff=3376&amp;oldid=prev</id>
		<title>Andr3w at 13:20, 9 August 2012</title>
		<link rel="alternate" type="text/html" href="http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;diff=3376&amp;oldid=prev"/>
				<updated>2012-08-09T13:20:17Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 13:20, 9 August 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 37:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 37:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;[[Category:Error]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Andr3w</name></author>	</entry>

	<entry>
		<id>http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;diff=1880&amp;oldid=prev</id>
		<title>Marek at 11:30, 19 July 2012</title>
		<link rel="alternate" type="text/html" href="http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;diff=1880&amp;oldid=prev"/>
				<updated>2012-07-19T11:30:08Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 11:30, 19 July 2012&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 7:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class = &amp;quot;link e-postgres&amp;quot;&amp;gt;ERROR: Aggregates not allowed in WHERE clause&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class = &amp;quot;link e-postgres&amp;quot;&amp;gt;ERROR: Aggregates not allowed in WHERE clause&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class = &amp;quot;link e-db2&amp;quot;&amp;gt;SQL0120N A WHERE clause, GROUP BY clause, SET clause, or SET transition-variable statement contains a column function.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class = &amp;quot;link e-db2&amp;quot;&amp;gt;SQL0120N A WHERE clause, GROUP BY clause, SET clause, or SET transition-variable statement contains a column function.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class = &amp;quot;link e-sqlserver&amp;gt;Msg 1013,&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;div class = &amp;quot;link e-sqlserver&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;&amp;quot;&lt;/ins&gt;&amp;gt;Msg 1013,&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Ambiguous column name 'name'.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Ambiguous column name 'name'.&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	<entry>
		<id>http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;diff=1877&amp;oldid=prev</id>
		<title>Marek: Created page with &quot;&lt;div class='err'&gt; &lt;div class=params&gt;schema:gisq&lt;/div&gt; &lt;div class = &quot;link e-oracle&quot;&gt;ORA-00934: group function is not allowed here&lt;/div&gt; &lt;div class = &quot;link e-mysql&quot;&gt;Error 1111 I...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.sqlzoo.net/w/index.php?title=Invalid_Group_function&amp;diff=1877&amp;oldid=prev"/>
				<updated>2012-07-19T11:20:52Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;div class=&amp;#039;err&amp;#039;&amp;gt; &amp;lt;div class=params&amp;gt;schema:gisq&amp;lt;/div&amp;gt; &amp;lt;div class = &amp;quot;link e-oracle&amp;quot;&amp;gt;ORA-00934: group function is not allowed here&amp;lt;/div&amp;gt; &amp;lt;div class = &amp;quot;link e-mysql&amp;quot;&amp;gt;Error 1111 I...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;div class='err'&amp;gt;&lt;br /&gt;
&amp;lt;div class=params&amp;gt;schema:gisq&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class = &amp;quot;link e-oracle&amp;quot;&amp;gt;ORA-00934: group function is not allowed here&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class = &amp;quot;link e-mysql&amp;quot;&amp;gt;Error 1111&lt;br /&gt;
Invalid use of group function&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class = &amp;quot;link e-sqlserver&amp;quot;&amp;gt;Msg 147 An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference. &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class = &amp;quot;link e-postgres&amp;quot;&amp;gt;ERROR: Aggregates not allowed in WHERE clause&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class = &amp;quot;link e-db2&amp;quot;&amp;gt;SQL0120N A WHERE clause, GROUP BY clause, SET clause, or SET transition-variable statement contains a column function.&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class = &amp;quot;link e-sqlserver&amp;gt;Msg 1013,&lt;br /&gt;
Ambiguous column name 'name'.&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt;Problem&amp;lt;/h2&amp;gt;&amp;lt;p&amp;gt;&lt;br /&gt;
We want to filter the results returned based on an &amp;lt;i&amp;gt;aggregate&amp;lt;/i&amp;gt;&lt;br /&gt;
function such as COUNT or SUM.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;&lt;br /&gt;
The WHERE clause may not be used for this. The WHERE conditions are&lt;br /&gt;
considered before the aggregation.&lt;br /&gt;
&amp;lt;/p&amp;gt;&amp;lt;h2&amp;gt;Solutions&amp;lt;/h2&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Put the condition into the HAVING clause, after the GROUP BY&lt;br /&gt;
    clause.&amp;lt;/li&amp;gt;&amp;lt;pre&amp;gt;SELECT winner FROM nobel&lt;br /&gt;
  GROUP BY winner&lt;br /&gt;
  HAVING COUNT(winner)&amp;gt;1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=sql class='tidy'&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang=sql class='setup'&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;SELECT winner FROM nobel&lt;br /&gt;
 WHERE COUNT(winner)&amp;gt;1&lt;br /&gt;
GROUP BY winner&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;ecomm e-mysql&amp;quot; style=&amp;quot;display: none&amp;quot;&amp;gt;In MySQL on LINUX the table names are case sensitive. This means that&lt;br /&gt;
the table &amp;lt;code&amp;gt;bbc&amp;lt;/code&amp;gt; exists but &amp;lt;code&amp;gt;Bbc&amp;lt;/code&amp;gt; gives an error.&lt;br /&gt;
This is a deviation from the SQL standard.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marek</name></author>	</entry>

	</feed>