Skip to content

Instantly share code, notes, and snippets.

@NickyBobby
Last active March 25, 2016 19:18
Show Gist options
  • Select an option

  • Save NickyBobby/3ab42ce13cc4ef9a4715 to your computer and use it in GitHub Desktop.

Select an option

Save NickyBobby/3ab42ce13cc4ef9a4715 to your computer and use it in GitHub Desktop.

What's the total revenue for all items? SELECT sum(revenue) FROM items; 3800

What's the average revenue for all items? SELECT avg(revenue) FROM items; 950.000

What's the minimum revenue for all items? SELECT min(revenue) FROM items; 500

What's the maximum revenue for all items? SELECT max(revenue) FROM items; 1200

What the count for items with a name? SELECT count(name) FROM items; 4

Write queries for the following:

Return all main courses. Hint: What ActiveRecord method would you use to get this? SELECT * FROM items WHERE course = 'main';

Return only the names of the main courses. SELECT name FROM items WHERE course = 'main';

Return the min and max value for the main courses. SELECT min(revenue), max(revenue) FROM items WHERE course = 'main';

What's the total revenue for all main courses? SELECT sum(revenue) FROM items WHERE course = 'main';

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