main
Matt Huntington 2 years ago
parent 496e526718
commit 08e88878ad

@ -0,0 +1,29 @@
![](/ga_cog.png)
---
Title: Computers & Televisions <br>
Type: Lab <br>
Creator: Thom Page <br>
Adapted By: Jerrica Bobadilla
---
# :computer: Computers & Televisions :tv:
For today's morning lab, you'll be getting practice with the SQL commands you just learned.
_NOTE!_ To create a new postgres database without connecting to psql, in terminal bash just run `createdb [databasename]` where [databasename] is whatever you want to name your new database.
### Activity
1. Start by working in the `computers.sql` file and follow the directions outlined there
1. Move onto the `televisions.sql` file and follow the directions outlined there
##### :red_circle: How to run .sql files in terminal:
- To run the .sql files, use the command: `psql database_name -f sql_file_name.sql`
- For example: `psql <db_name> -f <path_to_file>`
### Hungry for More?
If you finish both files, try out the [realty lab](./realty)!

@ -0,0 +1,26 @@
-- Open up psql and create a sql_lab database if you haven't already done so.
-- If you already have a sql_lab database, no need to create it again.
-- Write SQL commands under the prompts below, and run the file to get results.
-- In case there is already a computers table, drop it
-- Create a computers table
-- The table should have id, make, model, cpu_speed, memory_size,
-- price, release_date, photo_url, storage_amount, number_usb_ports,
-- number_firewire_ports, number_thunderbolt_ports
-- Insert 4 computers into the computers table
-- Select all entries from the computers table
-- HUNGRY FOR MORE?
-- Look at this afternoon's instructor notes and read on altering tables before attempting below
-- Alter the computers_models, removing the storage_amount column
-- and add storage_type and storage_size columns

@ -0,0 +1,26 @@
-- Open up psql and create a sql_lab database if you haven't already done so.
-- If you already have a sql_lab database, no need to create it again.
-- Write SQL commands under the prompts below, and run the file to get results.
-- In case there is already a televisions table, drop it
-- Create a televisions table
-- The table should have id, model_name, screen_size, resolution,
-- price, release_date, photo_url
-- Insert 4 televisions into the tv_models table
-- Select all entries from the tv_models table
-- HUNGRY FOR MORE?
-- Look at this afternoon's instructor notes and read on altering tables before attempting below
-- Alter the tv_models, removing the resolution column
-- and add vertical_resolution and horizontal_resolution columns

@ -0,0 +1,89 @@
![ga](/ga_cog.png)
# Carmen Sandiego
---
Title: Carmen Sandiego<br>
Type: Homework<br>
Modified by: Karolin Rafalski <br>
Competencies: Basic SQL<br>
---
## Introduction
#### Where In The World Is Carmen Sandiego?
We're going to use what we've learned already about searching with SQL commands, and apply it to chase down and capture an elusive and world-renowned thief, Carmen Sandiego. Follow the clues, use the documentation - write down **both** the SQL commands /queries you used and your answers to the clues (in the [find_carmen.sql](find_carmen.sql) file)- and figure out where Carmen's headed, so we can catch her and bring her in.
## Exercise
#### Requirements
- Use the [find_carmen.sql](find_carmen.sql) file as your "answer sheet"
- From the command line, let's create a new database called ```carmen``` and populate it with the SQL found in ```world.sql```
Use the postgres shell:
```
# Enter psql
psql
# Create database
CREATE DATABASE carmen;
# Connect to carmen
\c carmen
\i starter-code/world.SQL
```
Then, use the clues below to create the appropriate SQL queries to help you find Carmen and then, tell us where she's heading!! (Record your answers in the [find_carmen.sql](find_carmen.sql) file). Don't forget to git commit when you've found her!
### The Clues
- **Clue #1:** We recently got word that someone fitting Carmen Sandiego's description has been traveling through Southern Europe. She's most likely traveling someplace where she won't be noticed, so find the least populated country in Southern Europe, and we'll start looking for her there.
- **Clue #2:** Now that we're here, we have insight that Carmen was seen attending language classes in this country's officially recognized language. Check our databases and find out what language is spoken in this country, so we can call in a translator to work with you.
- **Clue #3:** We have new news on the classes Carmen attended: our gumshoes tell us she's moved on to a different country, a country where people speak *only* the language she was learning. Find out which nearby country speaks nothing but that language.
- **Clue #4:** We're booking the first flight out: maybe we've actually got a chance to catch her this time. There are only two cities she could be flying to in the country. One is named the *same* as the country that would be too obvious. We're following our gut on this one; find out what other city in that country she might be flying to.
<hr>
&#x1F534; COMMIT 1<br>
"Commit: CARMEN SANDIEGO - Halfway there! Hot on her trail."
<hr>
- **Clue #5:** Oh no, she pulled a switch: there are two cities with very similar names, but in totally different parts of the globe! She's headed to South America as we speak; go find a city whose name is *like* the one we were headed to, but doesn't end the same. Find out the city, and do another search for what country it's in. Hurry!
- **Clue #6:** We're close! Our South American agent says she just got a taxi at the airport, and is headed towards the capital! Look up the country's capital, and get there pronto! Send us the name of where you're headed and we'll follow right behind you!
- **Clue #7:** She knows we're on to her: her taxi dropped her off at the international airport, and she beat us to the boarding gates. We have one chance to catch her, we just have to know where she's heading and beat her to the landing dock.
- Lucky for us, she's getting cocky. She left us a note, and I'm sure she thinks she's very clever, but if we can crack it, we can finally put her where she belongs behind bars.
```
Our playdate of late has been unusually fun
As an agent, I'll say, you've been a joy to outrun.
And while the food here is great, and the people so nice!
I need a little more sunshine with my slice of life.
So I'm off to add one to the population I find
In a city of ninety-one thousand and now, eighty five.
```
<hr>
&#x1F534; COMMIT 2<br>
"Commit: CARMEN SANDIEGO - I found Carmen Sandiego"
<hr>
### Hungry for more?
Some of the entries have gotten a bit messed up. For example, the capital of Brazil is not `Bras�lia`, rather, it is Brasília. Update this entry to the correct spelling. Record your update, in the find_carmen.sql file (below `I found Carmen`), and do a query for one row and copy paste it to show the update.
Update any other two entries that have gotten messed up.
## Additional Resources
- [PostgreSQL tutorial](http://www.tutorialspoint.com/postgresql/)
- [PostgreSQL official documentation](http://www.postgresql.org/docs/)

@ -0,0 +1,65 @@
-- TEST COMMAND AND SAMPLE OUTPUT
-- Record your query (or queries, some clues require more than one) below the clue, then comment out the output below it
-- use two `-` to comment at the start of a line, or highlight the text and press `⌘/` to toggle comments
-- EXAMPLE: SELECT ALL FROM THE TABLE COUNTRY AND LIMIT IT TO ONE ENTRY
SELECT * FROM COUNTRY LIMIT 1;
-- -[ RECORD 1 ]--+--------------------------
-- code | AFG
-- name | Afghanistan
-- continent | Asia
-- region | Southern and Central Asia
-- surfacearea | 652090
-- indepyear | 1919
-- population | 22720000
-- lifeexpectancy | 45.9
-- gnp | 5976.00
-- gnpold |
-- localname | Afganistan/Afqanestan
-- governmentform | Islamic Emirate
-- headofstate | Mohammad Omar
-- capital | 1
-- code2 | AF
-- Clue #1: We recently got word that someone fitting Carmen Sandiego's description has been traveling through Southern Europe. She's most likely traveling someplace where she won't be noticed, so find the least populated country in Southern Europe, and we'll start looking for her there.
-- Clue #2: Now that we're here, we have insight that Carmen was seen attending language classes in this country's officially recognized language. Check our databases and find out what language is spoken in this country, so we can call in a translator to work with you.
-- Clue #3: We have new news on the classes Carmen attended our gumshoes tell us she's moved on to a different country, a country where people speak only the language she was learning. Find out which nearby country speaks nothing but that language.
-- Clue #4: We're booking the first flight out maybe we've actually got a chance to catch her this time. There are only two cities she could be flying to in the country. One is named the same as the country that would be too obvious. We're following our gut on this one; find out what other city in that country she might be flying to.
-- Clue #5: Oh no, she pulled a switch there are two cities with very similar names, but in totally different parts of the globe! She's headed to South America as we speak; go find a city whose name is like the one we were headed to, but doesn't end the same. Find out the city, and do another search for what country it's in. Hurry!
-- Clue #6: We're close! Our South American agent says she just got a taxi at the airport, and is headed towards the capital! Look up the country's capital, and get there pronto! Send us the name of where you're headed and we'll follow right behind you!
-- Clue #7: She knows we're on to her her taxi dropped her off at the international airport, and she beat us to the boarding gates. We have one chance to catch her, we just have to know where she's heading and beat her to the landing dock.
-- Lucky for us, she's getting cocky. She left us a note, and I'm sure she thinks she's very clever, but if we can crack it, we can finally put her where she belongs behind bars.
-- Our playdate of late has been unusually fun
-- As an agent, I'll say, you've been a joy to outrun.
-- And while the food here is great, and the people so nice!
-- I need a little more sunshine with my slice of life.
-- So I'm off to add one to the population I find
-- In a city of ninety-one thousand and now, eighty five.
-- We're counting on you, gumshoe. Find out where she's headed, send us the info, and we'll be sure to meet her at the gates with bells on.

File diff suppressed because it is too large Load Diff

@ -0,0 +1,110 @@
![](/ga_cog.png)
---
Title: Airplanes & Airports <br>
Type: Lab <br>
Created By: Matt Huntington<br>
Modified By: Jerrica Bobadilla
---
## Setup
1. Create a new database called `flights`, connect to it, and run the following code (given to you in the `flights.sql` file):
- _Note:_ To create a new postgres database without connecting to psql, in terminal bash just run `createdb [databasename]` where [databasename] is whatever you want to name your new database.
- _Note 2:_ After you create the database, you can then run this .sql file using `psql <db_name> -f <path_to_file>`
```sql
CREATE TABLE airlines (
id int,
name varchar(255) DEFAULT NULL,
alias varchar(255) DEFAULT NULL,
iata varchar(255) DEFAULT NULL,
icao varchar(255) DEFAULT NULL,
callsign varchar(255) DEFAULT NULL,
country varchar(255) DEFAULT NULL,
active varchar(255) DEFAULT NULL
);
CREATE TABLE airports (
id int,
name varchar(255) DEFAULT NULL,
city varchar(255) DEFAULT NULL,
country varchar(255) DEFAULT NULL,
iata_faa varchar(255) DEFAULT NULL,
icao varchar(255) DEFAULT NULL,
latitude varchar(255) DEFAULT NULL,
longitude varchar(255) DEFAULT NULL,
altitude varchar(255) DEFAULT NULL,
utc_offset varchar(255) DEFAULT NULL,
dst varchar(255) DEFAULT NULL,
tz varchar(255) DEFAULT NULL
);
CREATE TABLE routes (
airline_code varchar(255) DEFAULT NULL,
airline_id int DEFAULT NULL,
origin_code varchar(255) DEFAULT NULL,
origin_id int DEFAULT NULL,
dest_code varchar(255) DEFAULT NULL,
dest_id int DEFAULT NULL,
codeshare varchar(255) DEFAULT NULL,
stops int DEFAULT NULL,
equipment varchar(255) DEFAULT NULL
);
```
1. Connect to your `flights` database using your postgres app
1. Once inside the psql database (you'll know you're in the right one if your terminal says `flights=#`), run the following lines individually
**NOTE**: You will have to path to the csv files from wherever the postgres app opens up your database in terminal. For example, if it opens the postgres terminal at the root (`~`) and my SEIR-Ewoks folder is on my desktop, I would path to routes.csv like so: `./Desktop/SEIR-Ewoks/unit_4/w10d02/student_labs/lab_2/routes.csv`. Your path will look different depending on where your classroom repo is located.
> If you are able to use the `psql flights` terminal command to open the database, you can run that command from inside todays student_labs/afternoon folder and just copy paste the commands as given below.
```
\copy routes FROM 'routes.csv' DELIMITER ',' CSV
```
- You should get back `COPY 67663` if you were successful
```
\copy airports FROM 'airports.csv' DELIMITER ',' CSV
```
- You should get back `COPY 8107` if you were successful
```
\copy airlines FROM 'airlines.csv' DELIMITER ',' CSV
```
- You should get back `COPY 6048` if you were successful
1. You should now have seeded three tables with flight data!
## Activity
> Our **main goal is to find out how many flights go from NYC to Paris.**
### Hints
- The routes table has a column called `origin_id` and another called `dest_id`. These map to the `id` column in the airport table. Think about how to treat the `id`s as foreign keys.
- You're going to have to use the airports table twice in the same SQL statement. In order to tell which airport is the `destination` and which is the `origin`, you're going to have to temporarily rename the airports table like so:
```sql
/* note that once you rename a table, you MUST refer to it by its new name */
SELECT * FROM airports AS origin WHERE origin.city = 'New York';
/* later on in the SQL statement, when dealing with the destination, you should do the same for airports AS destination */
```
- Note that you'll only need to use the routes and airports tables
- Think about using aggregation and inner joins
### Steps to think about
1. Find all airports that originate from New York
1. Find all destination airports in Paris
1. Find out how many routes originate from New York
1. Find out how many routes have destinations in Paris
1. Try to decide which statements are necessary and find how to combine them to find out how many routes originate from New York and land in Paris!
## Stretch Goals
- Do this so that just the number appears as the result of only one SQL statement
- Which airlines travel from NYC to Paris?
- Find all the flights that leave NYC. Give a list of how many go to each destination city.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,37 @@
CREATE TABLE airlines (
id int,
name varchar(255) DEFAULT NULL,
alias varchar(255) DEFAULT NULL,
iata varchar(255) DEFAULT NULL,
icao varchar(255) DEFAULT NULL,
callsign varchar(255) DEFAULT NULL,
country varchar(255) DEFAULT NULL,
active varchar(255) DEFAULT NULL
);
CREATE TABLE airports (
id int,
name varchar(255) DEFAULT NULL,
city varchar(255) DEFAULT NULL,
country varchar(255) DEFAULT NULL,
iata_faa varchar(255) DEFAULT NULL,
icao varchar(255) DEFAULT NULL,
latitude varchar(255) DEFAULT NULL,
longitude varchar(255) DEFAULT NULL,
altitude varchar(255) DEFAULT NULL,
utc_offset varchar(255) DEFAULT NULL,
dst varchar(255) DEFAULT NULL,
tz varchar(255) DEFAULT NULL
);
CREATE TABLE routes (
airline_code varchar(255) DEFAULT NULL,
airline_id int DEFAULT NULL,
origin_code varchar(255) DEFAULT NULL,
origin_id int DEFAULT NULL,
dest_code varchar(255) DEFAULT NULL,
dest_id int DEFAULT NULL,
codeshare varchar(255) DEFAULT NULL,
stops int DEFAULT NULL,
equipment varchar(255) DEFAULT NULL
);

File diff suppressed because it is too large Load Diff

@ -0,0 +1,98 @@
-- get All airports in New York
SELECT * FROM airports where city = 'New York';
-- get all airports in Paris
SELECT * FROM airports where city = 'Paris;
-- note only JFK has international flights
-- grab icao for New York
SELECT icao FROM airports WHERE city = 'New York';
-- grab icao for Paris
SELECT icao FROM airports WHERE city = 'Paris';
-- select all fields where destination code and origin code are from ny to paris
select * from routes where dest_code = 'CDG' AND origin_code = 'JFK';
-- use aliases when choosing same table
SELECT icao FROM airports AS origin WHERE origin.city = 'New York';
SELECT icao FROM airports AS destination WHERE destination.city = Paris;
-- start joining tables
SELECT * FROM routes INNER JOIN WHERE origin.icao = JFK AND destination.icao = CDG
-- look more at the details of data
SELECT * FROM routes INNER JOIN airports AS origin ON origin.city = 'New York' limit 5;
SELECT * FROM routes INNER JOIN airports AS destination ON destination.city = Paris limit 5;
-- narrowing things down to what we were looking for
SELECT * FROM routes INNER JOIN airports ON airport.city = 'New York' AND
routes INNER JOIN airports AS destination ON destination.city = Paris ;
-- cleaning up the formatting
SELECT
COUNT(*)
FROM
routes
INNER JOIN
airports
AS
origin
ON
origin.iata_faa = routes.origin_code
INNER JOIN
airports AS destination
ON
destination.iata_faa = routes.dest_code
WHERE
origin.city = 'New York'
AND
destination.city = Paris;
-- more troubleshooting
SELECT COUNT(*) FROM routes INNER JOIN airports as destination ON destination.iata_faa = routes.dest_code WHERE destination.city = 'Paris';
-- more formatting
SELECT
*
FROM
routes
INNER JOIN
airports
AS
origin
ON
origin.iata_faa = routes.origin_code
INNER JOIN
airports AS destination
ON
destination.iata_faa = routes.dest_code
WHERE
origin.city = 'New York'
AND
destination.city = Paris;
-- final`
SELECT
COUNT(*)
FROM
routes
JOIN
airports
AS
origin
ON
origin.iata_faa = routes.origin_code
JOIN
airports
AS
destination
ON
destination.iata_faa = routes.dest_code
WHERE
origin.city = 'New York'
AND
destination.city = 'Paris';

@ -0,0 +1,79 @@
![ga](/ga_cog.png)
# NFL
---
Title: NFL <br>
Type: Homework<br>
Modified by: Karolin Rafalski, Thom Page <br>
Competencies: Basic SQL<br>
---
### Schema and seed
You are provided with a schema file [schema.sql](nfl_seed_data/schema.sql) and two seed files
`players.sql`, `teams.sql` that are also in the `nfl_seed_data` folder. Create a new database called `nfl` and use the schema and seed file to populate your database.
<hr>
:red_circle: "Commit: NFL db seeded"
<hr>
Record your answers to Step 3 in a file called [nfl.sql](nfl.sql).
_Challenge_: Complete each part with a single SQL expression. That is
possible, but for some queries, it will involve learning how to use compound SQL
expressions.
### Queries
Some queries may require more than one command (i.e. you may need to get information about a team before you can complete a query for players). Test each command in PSQL to make sure it is correct.
1. List the names of all NFL teams
2. List the stadium name and head coach of all NFC teams
3. List the head coaches of the AFC South
4. The total number of players in the NFL
<hr>
:red_circle: "Commit: NFL queries 1"
<hr>
5. The team names and head coaches of the NFC North and AFC East
6. The 50 players with the highest salaries
7. The average salary of all NFL players
8. The names and positions of players with a salary above 10_000_000
<hr>
:red_circle: "Commit: NFL queries 2"
<hr>
9. The player with the highest salary in the NFL
10. The name and position of the first 100 players with the lowest salaries
11. The average salary for a DE in the nfl
<hr>
:red_circle: "Commit: NFL queries 3"
<hr>
## Hungry For More
For these you will need to query two tables at the same time. In order to do some parts you will need to research commands using dot notation that we did not cover in class.
EXAMPLE
> The names of all the players on the Buffalo Bills
```sql
SELECT players.name, teams.name
FROM players, teams
WHERE players.team_id=teams.id AND teams.name LIKE 'Buffalo Bills';
```
13. The total salary of all players on the New York Giants
14. The player with the lowest salary on the Green Bay Packers
<hr>
:red_circle: "Commit: NFL - HFM"
<hr>

@ -0,0 +1,39 @@
-- 1. List the names of all NFL teams'
-- 2. List the stadium name and head coach of all NFC teams
-- 3. List the head coaches of the AFC South
-- 4. The total number of players in the NFL
-- 5. The team names and head coaches of the NFC North and AFC East
-- 6. The 50 players with the highest salaries
-- 7. The average salary of all NFL players
-- 8. The names and positions of players with a salary above 10_000_000
-- 9. The player with the highest salary in the NFL
-- 10. The name and position of the first 100 players with the lowest salaries
-- 11. The average salary for a DE in the nfl
-- 12. The names of all the players on the Buffalo Bills
-- 13. The total salary of all players on the New York Giants
-- 14. The player with the lowest salary on the Green Bay Packers

File diff suppressed because it is too large Load Diff

@ -0,0 +1,20 @@
drop table if exists players;
drop table if exists teams;
create table teams(
id serial primary key,
name varchar(255) not null,
stadium varchar(255),
division varchar(255),
conference varchar(255),
head_coach varchar(255),
active boolean
);
create table players(
id serial primary key,
name varchar(255) not null,
position varchar(255),
salary integer,
team_id integer references teams
);

@ -0,0 +1,32 @@
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Buffalo Bills', 'Ralph Wilson Stadium', 'Doug Marrone', 'AFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Miami Dolphins', 'Sun Life Stadium', 'Joe Philbin', 'AFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('New England Patriots', 'Gillette Stadium', 'Bill Belichick', 'AFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('New York Jets', 'MetLife Stadium', 'Rex Ryan', 'AFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Baltimore Ravens', 'M&T Bank Stadium', 'John Harbaugh', 'AFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Cincinnati Bengals', 'Paul Brown Stadium', 'Marvin Lewis', 'AFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Cleveland Browns', 'FirstEnergy Stadium', 'Mike Pettine', 'AFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Pittsburgh Steelers', 'Heinz Field', 'Mike Tomlin', 'AFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Houston Texans', 'NRG Stadium', 'Bill OBrien', 'AFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Indianapolis Colts', 'Lucas Oil Stadium', 'Chuck Pagano', 'AFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Jacksonville Jaguars', 'EverBank Field', 'Gus Bradley', 'AFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Tennessee Titans', 'LP Field', 'Ken Whisenhunt', 'AFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Denver Broncos', 'Sports Authority Field', 'John Fox', 'AFC', 'West', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Kansas City Chiefs', 'Arrowhead Stadium', 'Andy Reid', 'AFC', 'West', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Oakland Raiders', 'O.co Coliseum', 'Tony Sparano', 'AFC', 'West', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('San Diego Chargers', 'Qualcomm Stadium', 'Mike McCoy', 'AFC', 'West', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Dallas Cowboys', 'AT&T Stadium', 'Jason Garrett', 'NFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('New York Giants', 'MetLife Stadium', 'Tom Coughlin', 'NFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Philadelphia Eagles', 'Lincoln Financial Field', 'Chip Kelly', 'NFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Washington Redskins', 'FedExField', 'Jay Gruden', 'NFC', 'East', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Chicago Bears', 'Soldier Field', 'Marc Trestman', 'NFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Detroit Lions', 'Ford Field', 'Jim Caldwell', 'NFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Green Bay Packers', 'Lambeau Field', 'Mike McCarthy', 'NFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Minnesota Vikings', 'TCF Bank Stadium', 'Mike Zimmer', 'NFC', 'North', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Atlanta Falcons', 'Georgia Dome', 'Mike Smith', 'NFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Carolina Panthers', 'Bank of America Stadium', 'Ron Rivera', 'NFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('New Orleans Saints', 'Mercedes-Benz Superdome', 'Sean Payton', 'NFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Tampa Bay Buccaneers', 'Raymond James Stadium', 'Lovie Smith', 'NFC', 'South', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Arizona Cardinals', 'University of Phoenix Stadium', 'Bruce Arians', 'NFC', 'West', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('St. Louis Rams', 'Edward Jones Dome', 'Jeff Fisher', 'NFC', 'West', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('San Francisco 49ers', 'Levis Stadium', 'Jim Harbaugh', 'NFC', 'West', 'true');
INSERT INTO teams (name, stadium, head_coach, conference, division, active) VALUES ('Seattle Seahawks', 'CenturyLink Field', 'Pete Carroll', 'NFC', 'West', 'true');

@ -0,0 +1,83 @@
![ga](/ga_cog.png)
# Realty
---
Title: Realty <br>
Source: WDI-Skywalker (2015)<br>
Modified by: Karolin Rafalski, Thom Page <br>
Competencies: SQL queries, aggregation
---
## Learning Objectives
- Practice creating a database from the command line
- Practice seeding a database using SQL
- Practice using the Command Line API of postgresql
- Practice querying a database using SQL
## Activity
#### Step 1 - Create a new database
- Create a new database called `realty_db`.
- _NOTE!_ To create a new postgres database without connecting to psql, in terminal bash just run `psql [databasename]` where [databasename] is whatever you want to name your new database.
#### Step 2 - Create a Schema
- Use the given schema file named `realty_schema.sql` and create tables in your realty database which should model `Apartments`, `Offices` and `Storefronts`. They should have the following properties:
##### An Apartment should have:
- id - serial primary key
- apartment_number - integer
- bedrooms - integer
- bathrooms - integer
- address - varchar
- tenant - varchar
- occupied - boolean
- sq_ft - integer
- price - integer
##### An Office should have:
- id - serial primary key
- office_number - integer
- floors - integer
- sq_ft - integer
- cubicles - integer
- bathrooms - integer
- address - varchar
- company - varchar
- occupied - boolean
- price - integer
##### A Storefront should have:
- address - varchar
- occupied - boolean
- price - integer
- kitchen - boolean
- sq_ft - integer
- owner - varchar
- outdoor_seating - boolean
- Load the seed file into your database from the command line. Use the `psql` shell to inspect your schema.
#### Step 3 - Define a seed file and seed your database
- In a SQL file named `realty_seed.sql`, write the proper INSERT commands that will add new entries into your apartment, office and storefront tables. You should create at least 3 entries for each table. Vary the attributes of each entry so no two are alike. From the command line, load this seed file into your database.
#### Step 4 - Queries
- In the given `realty.sql` file, write the SQL commands you would use to retrieve the following information from your database. Test each command in PSQL to make sure it is correct:
- The average square footage of all offices.
- The total number of apartments.
- The apartments where there is no tenant
- The names of all of the companies
- The number of cubicles and bathrooms in the 3rd office
- The storefronts that have kitchens
- The storefront with the highest square footage and outdoor seating
- The office with the lowest number of cubicles
- The office with the most cubicles and bathrooms

@ -0,0 +1,25 @@
-- 1. The average square footage of all offices.
-- 2. The total number of apartments.
-- 3. The apartments where there is no tenant
-- 4. The names of all of the companies
-- 5. The number of cubicles and bathrooms in the 3rd office
-- 6. The storefronts that have kitchens
-- 7. The storefront with the highest square footage and outdoor seating
-- 8. The office with the lowest number of cubicles
-- 9. The office with the most cubicles and bathrooms

@ -0,0 +1 @@
-- enter your schema for apartments, offices and storefronts below

@ -0,0 +1 @@
--enter your seed data below
Loading…
Cancel
Save