Difference between revisions of "SELECT .. GROUP BY"
|(One intermediate revision by the same user not shown)|
Latest revision as of 12:07, 23 April 2014
SELECT .. GROUP BY
Host cities and continents for the Olympics Games are stored in the table
Notice that Europe appears in the table twice:
DROP TABLE games
CREATE TABLE emp( id INTEGER, name VARCHAR(20), DATE DATE); INSERT INTO emp VALUES (1,'a','jan,10,2014'); INSERT INTO emp VALUES (2,'b','jan,11,2014'); INSERT INTO emp VALUES (3,'c','jan,10,2014'); INSERT INTO emp VALUES (4,'d','jan,11,2014');
In a GROUP BY statement only distinct values are shown for the column in the GROUP BY. This example shows the continents hosting the Olympics with the count of the number of games held.
SELECT continent, COUNT(yr) FROM games GROUP BY continent