Skip to content

Instantly share code, notes, and snippets.

@clayenga
Created November 19, 2012 18:26
Show Gist options
  • Select an option

  • Save clayenga/4112534 to your computer and use it in GitHub Desktop.

Select an option

Save clayenga/4112534 to your computer and use it in GitHub Desktop.
SQL question (total book prices for each genre)
books:
id | title | price | genre_id
--------------------------------------------------
1 | Gone With the Wind | 15 | 1
2 | The Lord of the Rings | 30 | 2
3 | The Hobbit | 10 | 2
4 | Pride and Predjudice | 10 | 1
5 | Complete Sherlock Holmes | 9 | 4
genres:
id | name |
------------------------------
1 | Romance
2 | Fantasy
3 | Comedy
4 | Mystery
Write a query to get, for each genre (category), the sum of prices of books in that genre.
@clayenga

clayenga commented Oct 8, 2013

Copy link
Copy Markdown
Author

Follow-up question, unless the original solution already does it:

How would you change the query so that it includes (Comedy, 0) in the results?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment