Coder Social home page Coder Social logo

apartment-lab-sql's Introduction

Apartment Lab (SQL Practice)

For these challenges, you'll be working with two tables, owners and properties. Keep this relationship in mind when designing your schema: one owner can have many properties.

Getting Started

  1. Create a database called apartmentlab.
  2. Using the apartmentlab database, create two tables, one for owners and one for properties. See the next section for schema specs.

Schema

  • The owners table should consist of:

    • id (this should be the primary key as well as a unique number that increments automatically)
    • name
    • age
  • The properties table should consist of:

    • id (this should be the primary key as well as a unique number that increments automatically)
    • name
    • num_units
    • owner_id (this should be a foreign key that references the owners table)

Challenges

In a markdown file, write the SQL statements required to solve the following tasks. Make sure to test your queries in the psql terminal! Remember you can type \? in the psql terminal for a list of commands.

  1. Show all the psql users. (Hint: Look for a command to show roles)
  2. Show all the tables in your apartmentlab database.
  3. Show all the data in the owners table.
  4. Add three owners: Donald (age 56), Elaine (age 24), and Emma (age 36).
  5. Show the names of all owners.
  6. Show the ages of all of the owners in ascending order.
  7. Show the name of an owner whose name is Donald.
  8. Show the age of all owners who are older than 30.
  9. Show the name of all owners whose name starts with an "E".
  10. Add an owner named John who is 33 years old.
  11. Add an owner named Jane who is 43 years old.
  12. Change Jane's age to 30.
  13. Change Jane's name to Janet.
  14. Delete the owner named Janet.
  15. Add a property named Archstone that has 20 units.
  16. Add two more properties with names and number of units of your choice.
  17. Show all of the properties in alphabetical order that are not named Archstone.
  18. Count the total number of rows in the properties table.
  19. Show the highest age of all the owners.
  20. Show the names of the first three owners in your owners table.
  21. Use a FULL OUTER JOIN to show all of the information from the owners table and the properties table.
  22. Update at least one of your properties to belong to the owner with id 1.
  23. Use an INNER JOIN to show all of the owners with associated properties.
  24. Use a CROSS JOIN to show all possible combinations of owners and properties.

Stretch Challenges

Note: You may need to research documentation for these challenges.

  1. In the properties table, change the name of the column name to property_name.
  2. Count the total number of properties where the owner_id is between 1 and 3.

apartment-lab-sql's People

Contributors

cameronjacoby avatar abeytaadam avatar rycwilson avatar bgveenstra avatar eerwitt avatar

Watchers

James Cloos avatar  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.