<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://sqlzoo.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://sqlzoo.net/w/index.php?title=Using_SUM,_Count,_MAX,_DISTINCT_and_ORDER_BY&amp;feed=atom&amp;action=history</id>
		<title>Using SUM, Count, MAX, DISTINCT and ORDER BY - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://sqlzoo.net/w/index.php?title=Using_SUM,_Count,_MAX,_DISTINCT_and_ORDER_BY&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Using_SUM,_Count,_MAX,_DISTINCT_and_ORDER_BY&amp;action=history"/>
		<updated>2013-05-23T04:34:36Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.4</generator>

	<entry>
		<id>http://sqlzoo.net/w/index.php?title=Using_SUM,_Count,_MAX,_DISTINCT_and_ORDER_BY&amp;diff=793&amp;oldid=prev</id>
		<title>Connor: Created page with &quot;&lt;h3&gt;BBC Country Profile&lt;/h3&gt;    &lt;h2&gt;Aggregates&lt;/h2&gt;    &lt;p&gt;The functions &lt;code&gt;SUM&lt;/code&gt;, &lt;code&gt;COUNT&lt;/code&gt;, &lt;code&gt;MAX&lt;/code&gt;   and &lt;code&gt;AVG&lt;/code&gt; are &quot;aggregates&quot;, each   ...&quot;</title>
		<link rel="alternate" type="text/html" href="http://sqlzoo.net/w/index.php?title=Using_SUM,_Count,_MAX,_DISTINCT_and_ORDER_BY&amp;diff=793&amp;oldid=prev"/>
				<updated>2012-07-11T09:19:20Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;h3&amp;gt;BBC Country Profile&amp;lt;/h3&amp;gt;    &amp;lt;h2&amp;gt;Aggregates&amp;lt;/h2&amp;gt;    &amp;lt;p&amp;gt;The functions &amp;lt;code&amp;gt;SUM&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;COUNT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt;   and &amp;lt;code&amp;gt;AVG&amp;lt;/code&amp;gt; are &amp;quot;aggregates&amp;quot;, each   ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;h3&amp;gt;BBC Country Profile&amp;lt;/h3&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;h2&amp;gt;Aggregates&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;p&amp;gt;The functions &amp;lt;code&amp;gt;SUM&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;COUNT&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;MAX&amp;lt;/code&amp;gt;&lt;br /&gt;
  and &amp;lt;code&amp;gt;AVG&amp;lt;/code&amp;gt; are &amp;quot;aggregates&amp;quot;, each&lt;br /&gt;
  may be applied to a numeric attribute resulting in a single row&lt;br /&gt;
  being returned by the query. (These functions are even more&lt;br /&gt;
  useful when used with the &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; clause.)&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;h2&amp;gt;Distinct&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;p&amp;gt;By default the result of a &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; may contain duplicate rows.&lt;br /&gt;
  We can remove these duplicates using the &amp;lt;code&amp;gt;DISTINCT&amp;lt;/code&amp;gt; key word.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;h2&amp;gt;Order by&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;p&amp;gt;ORDER BY permits us to see the result of a SELECT in any&lt;br /&gt;
  particular order. We may indicate ASC or DESC for ascending (smallest&lt;br /&gt;
  first, largest last) or descending order.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
The total &amp;lt;code&amp;gt;population&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;GDP&amp;lt;/code&amp;gt;&lt;br /&gt;
of Europe.&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT SUM(population), SUM(gdp)&lt;br /&gt;
  FROM bbc&lt;br /&gt;
  WHERE region = 'Europe'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='ans'&amp;gt;&lt;br /&gt;
SELECT SUM(population), SUM(gdp)&lt;br /&gt;
  FROM bbc&lt;br /&gt;
  WHERE region = 'Europe'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
What are the regions?&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT DISTINCT region FROM bbc&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='ans'&amp;gt;&lt;br /&gt;
SELECT DISTINCT region FROM bbc&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class='qu'&amp;gt;&lt;br /&gt;
Show the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;population&amp;lt;/code&amp;gt;&lt;br /&gt;
for each country with&lt;br /&gt;
a population of more than 100000000. Show countries in descending order of&lt;br /&gt;
population.&lt;br /&gt;
&amp;lt;source lang='sql' class='def'&amp;gt;&lt;br /&gt;
SELECT name, population&lt;br /&gt;
  FROM bbc&lt;br /&gt;
  WHERE population &amp;gt; 100000000&lt;br /&gt;
  ORDER BY population DESC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang='sql' class='ans'&amp;gt;&lt;br /&gt;
SELECT name, population&lt;br /&gt;
  FROM bbc&lt;br /&gt;
  WHERE population &amp;gt; 100000000&lt;br /&gt;
  ORDER BY population DESC&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>Connor</name></author>	</entry>

	</feed>