The tow lot app you built earlier has been in use for a few weeks, and the owner has some questions about the data that is now entered into it. Run rake db:setup
to create the database and load this data, then open a rails console
and write a single ActiveRecord query to achieve each of the following objectives. Record your finished queries in a separate file.
Note: "Vehicle" here only refers to records in the vehicles
table (i.e. not tow trucks).
- Get a list of all tow trucks.
- Get the vehicle with ID 3.
- Get the vehicle with VIN D0985DF1593A350A4.
- Get a list of all vehicles sorted by acquisition date.
- Get a list of all silver vehicles, ordered alphabetically by make.
- Get a list of all red Honda vehicles that are cars.
- Get a count of all vehicles that are motorcycles.
- Get a count of vehicles that are currently on the lot (i.e. not released).
- Get a list of all tow trucks whose mileage is over 200,000.
- Get a list of all tow trucks whose last service was more than 8 months ago.
- Get the average tow fee across all vehicles.
- Get the top 3 vehicles with the highest tow fees.
- Get all vehicles that have a fee assessed which has not been paid.
- Get a list of all released vehicles, sorted by most recently released.
- Get a list of all vehicles that have notes.
- Get the VINs of all vehicles manufactured before the year 2000.
- Get the make, model, and year of all silver vehicles, ordered by year.
- Get the total income from all vehicles (i.e. sum of all fees that are paid).