Exercise: SQL Aggregate Query

These queries should be run against the Open Source Shakespeare database, which has been uploaded to the schema shakespeare on the Kropotkin server.

Each query should be run against a single table (i.e, no joins are necessary). You will not need to use the wordform table to answer any of these questions. All of these queries require the use of aggregate functions. Most require the use of the GROUP BY clause, as well.

  1. How many words are there in all of Shakespeare’s works?
  2. The works in the OpenSourceShakespeare database are imported from other projects that provide public domain works in electronic format. Show the sources and number of works provided by each source.
  3. Now show only the source providing the most works.
  4. How many works did Shakespeare publish in each genre, and what is the earliest and latest publication year for each genre? Sort the results by genre code.
  5. For each year, what is the average number of words in a comedy. Sort your results by year.
  6. What is the charid and number of works the character appears in for all characters that appear in more than one work. Order the results from most to least works appeared in, then alphabetically by charid.
  7. Excluding the Sonnets, what is the workid and chapter count of the works with more than 25 chapters? NOTE: Because the chapter (scene) numbering restarts for each section (act), you cannot rely on the chapter number (i.e., the value of the chapter field) to answer this question.
  8. In what years did Shakespeare produce works in more than one genre?