Giter Site home page Giter Site logo

lab-rails-activerecord-finders's Introduction

Lab: Find Carmen Sandiego Again... with ActiveRecord!!

Part I - Find Carmen Sandiego

Repeat the previous exercise but this time let's use the ActiveRecord query interface to find Carmen Sandiego.

You DO NOT need to create the database NOR load the data again.

Feel free to re-use the SQL solution of the previous exercise and translate the SQL queries into ActiveRecord queries.

Part II - Extra challenges

Please use ActiveRecord queries to solve the following puzzles:

  1. List the distinct regions in the Country table.

  2. How many countries are located in European regions?

  3. Find the total population of all countries group by regions.

  4. Use one query to answer the following 2 questions

  5. Find the countries which have the most spoken languages used (Bonus: show the country names)

  6. Find the maximum number of languages you can use in one country

  7. Find all the Asia countries that went independent from 1940 to 1950. Order the result by the year of independence.

  8. Find all the countries that do not use English at all (Bonus: show the country names)

Instructions

  1. Fork and Clone
  2. In your local lab folder, do cd code/carmen.
  3. You should NOT change anything in the code/carmen folder.
  4. Run rails c and you will be inside the Rails console. Here you can use the ActiveRecord finder methods to query for data.
  5. Try to run the query City.take(1) to ensure everything is in order. You should see a similar output like this one:
Running via Spring preloader in process 26598
Loading development environment (Rails 4.2.1)
irb(main):001:0> City.take(1)
  City Load (0.4ms)  SELECT  "city".* FROM "city" LIMIT 1
=> [#<City id: 1, name: "Kabul", countrycode: "AFG", district: "Kabol", population: 1780000>]
irb(main):002:0> 

Deliverable

  1. Collect all your ActiveRecord queries in a file called query.rb under the repo root folder (where you find this README).
  2. Submit a pull request

lab-rails-activerecord-finders's People

Contributors

dshcheung avatar sytong avatar

Watchers

James Cloos avatar Jens H. Nielsen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.