Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Database Question The SQL statements that answer these 3 questions. please keep the answer simple will give thumbs up thank you :)! I will add

Database Question

The SQL statements that answer these 3 questions. please keep the answer simple will give thumbs up thank you :)!

I will add the sql data and table.sql below the IMAGE

image text in transcribed

LINK TO SQL DATA (had to add a space in between so it does not get blocked)

https://drive.go ogle.com/file/d/1qHCkrods5K2V1syyS5IG6-Eb_3QQmud7/view?usp=sharing

Table.sq:

-- MySQL Script generated by MySQL Workbench -- Sun Feb 21 00:00:31 2021 -- Model: New Model Version: 1.0 -- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- ----------------------------------------------------- -- Schema mydb -- -----------------------------------------------------

-- ----------------------------------------------------- -- Table state -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS state ( state_id INT NOT NULL AUTO_INCREMENT, name VARCHAR(45) NOT NULL, abb VARCHAR(2) NOT NULL, PRIMARY KEY (state_id), UNIQUE INDEX abb_UNIQUE (abb ASC)) ENGINE = InnoDB;

-- ----------------------------------------------------- -- Table address -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS address ( address_id INT NOT NULL AUTO_INCREMENT, street1 VARCHAR(45) NOT NULL, street2 VARCHAR(45) NULL, city VARCHAR(45) NOT NULL, zip VARCHAR(5) NOT NULL, state_id INT NOT NULL, PRIMARY KEY (address_id), INDEX FK_ADDRESS_STATE_IDX (state_id ASC), CONSTRAINT FK_ADDRESS_STATE FOREIGN KEY (state_id) REFERENCES state (state_id) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;

-- ----------------------------------------------------- -- Table person -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS person ( person_id INT NOT NULL AUTO_INCREMENT, first_name VARCHAR(45) NOT NULL, last_name VARCHAR(45) NOT NULL, sex VARCHAR(1) NOT NULL, dob DATETIME, address_id INT NULL, PRIMARY KEY (person_id), INDEX FK_PERSON_ADDRESS_IDX (address_id ASC), CONSTRAINT FK_PERSON_ADDRESS FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;

-- ----------------------------------------------------- -- Table branch -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS branch ( branch_no VARCHAR(5) NOT NULL, address_id INT NOT NULL, PRIMARY KEY (branch_no), INDEX FK_BRANCH_ADDRESS_IDX (address_id ASC) COMMENT ' ', UNIQUE INDEX ADDRESS_ID_UNIQUE (address_id ASC), CONSTRAINT FK_BRANCH_ADDRESS FOREIGN KEY (address_id) REFERENCES address (address_id) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;

-- ----------------------------------------------------- -- Table staff -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS staff ( staff_no VARCHAR(5) NOT NULL, person_id INT NOT NULL, position VARCHAR(45) NULL, salary INT NULL, branch_no VARCHAR(5) NOT NULL, PRIMARY KEY (staff_no), INDEX FK_STAFF_PERSON_IDX (person_id ASC), UNIQUE INDEX PERSON_ID_UNIQUE (person_id ASC), INDEX fk_staff_branch1_idx (branch_no ASC), CONSTRAINT FK_STAFF_PERSON FOREIGN KEY (person_id) REFERENCES person (person_id) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_staff_branch1 FOREIGN KEY (branch_no) REFERENCES branch (branch_no) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

Q4) (15pts) Show clients that have 3 or more properties for rent. Order by the number of properties for rent in descending order. first name last_name client_properties 4 I Heidi | Nicolas Evelia Deon Elmer | Reggie | Coffin Hetherington | Patty | Bridgett | Hodak | Sartor 31 31 31 31 6 rows in set 05) (20pts) Show the properties for rent if that property's rent is (1) larger than the average rent for all other properties combined. (2) Limit the result to properties that have a client number (i.e. client_no cannot be null). Your query should also show by how much the rent is higher for each property. Order by the rent difference property_no prop_type staff_no | client_no rooms state difference PR512 | PR232 | PR875 | PR127 1PR655 | PR131 | PR810 PR343 | PR431 Flat | Condo | Condo | Flat House | Flat Flat | Flat House II SG530 | SL557 | SQ537 | NULL | SG508 | NULL | SQ574 | NULL | SQ551 IT | CR228 | CR191 | CR147 | CR148 | CR195 | CR244 | CR170 | CR222 | CR183 | Oklahoma | Georgia | North Carolina 15 | Michigan | 2 | Alaska 18 | Florida | Minnesota 13 | Maryland 11 | Michigan III 1.2600 19.26001 59.2600 85.26001 150.2600 173.2600 228.26001 255.2600 390.26001 1 41 rows in set 06) (15pts) Show properties for sale, the property's state, the property's branch, and the state of that branch. Order by the rent from highest to lowest. Note that the branch and property states may be different addresses. To distinguish between the addresses, the query must use two independent copies of the address and state tables. The following query uses myTable twice as two separate copies. SELECT * FROM myTable t1, myTable t2.... WHERE ... Bonus Question: (5pts) if you wrote Q6 using JOIN, rewrite using WHERE. If you used WHERE, rewrite using JOIN. property_no prop_type | rooms 7 | 2 I PR200 | PR901 PR173 | PR838 | PR797 | PR169 IPR575 | PR720 | PR656 | PR254 PR854 | PR859 1 Flat | Flat | House | Condo | Condo House | Flat | Flat | Flat | Flat Condo | House i rent Property State | staff_no | branch_no | Branch State 24 | Nevada | SQ523 B623 | Pennsylvania 31 | Vermont ISL569 B647 | Florida 59 | Wyoming | SG570 B911 | Colorado 72 | Minnesota | S0541 | B745 | New Mexico 79 | Wyoming | SQ536 B623 | Pennsylvania 88 | Wyoming IS0581 B714 | North Dakota 155 | Massachusetts | SG535 B632 | Louisiana 161 | West Virginia | S0574 B647 | Florida 174 | North Dakota | SL584 B424 | Kentucky 236 | Iowa | S0504 | B960 | Rhode Island 265 | Arizona | SG516 | B190 | Vermont 296 | Rhode Island | SG527 B647 | Florida i I I 1 i i 114 rows Q4) (15pts) Show clients that have 3 or more properties for rent. Order by the number of properties for rent in descending order. first name last_name client_properties 4 I Heidi | Nicolas Evelia Deon Elmer | Reggie | Coffin Hetherington | Patty | Bridgett | Hodak | Sartor 31 31 31 31 6 rows in set 05) (20pts) Show the properties for rent if that property's rent is (1) larger than the average rent for all other properties combined. (2) Limit the result to properties that have a client number (i.e. client_no cannot be null). Your query should also show by how much the rent is higher for each property. Order by the rent difference property_no prop_type staff_no | client_no rooms state difference PR512 | PR232 | PR875 | PR127 1PR655 | PR131 | PR810 PR343 | PR431 Flat | Condo | Condo | Flat House | Flat Flat | Flat House II SG530 | SL557 | SQ537 | NULL | SG508 | NULL | SQ574 | NULL | SQ551 IT | CR228 | CR191 | CR147 | CR148 | CR195 | CR244 | CR170 | CR222 | CR183 | Oklahoma | Georgia | North Carolina 15 | Michigan | 2 | Alaska 18 | Florida | Minnesota 13 | Maryland 11 | Michigan III 1.2600 19.26001 59.2600 85.26001 150.2600 173.2600 228.26001 255.2600 390.26001 1 41 rows in set 06) (15pts) Show properties for sale, the property's state, the property's branch, and the state of that branch. Order by the rent from highest to lowest. Note that the branch and property states may be different addresses. To distinguish between the addresses, the query must use two independent copies of the address and state tables. The following query uses myTable twice as two separate copies. SELECT * FROM myTable t1, myTable t2.... WHERE ... Bonus Question: (5pts) if you wrote Q6 using JOIN, rewrite using WHERE. If you used WHERE, rewrite using JOIN. property_no prop_type | rooms 7 | 2 I PR200 | PR901 PR173 | PR838 | PR797 | PR169 IPR575 | PR720 | PR656 | PR254 PR854 | PR859 1 Flat | Flat | House | Condo | Condo House | Flat | Flat | Flat | Flat Condo | House i rent Property State | staff_no | branch_no | Branch State 24 | Nevada | SQ523 B623 | Pennsylvania 31 | Vermont ISL569 B647 | Florida 59 | Wyoming | SG570 B911 | Colorado 72 | Minnesota | S0541 | B745 | New Mexico 79 | Wyoming | SQ536 B623 | Pennsylvania 88 | Wyoming IS0581 B714 | North Dakota 155 | Massachusetts | SG535 B632 | Louisiana 161 | West Virginia | S0574 B647 | Florida 174 | North Dakota | SL584 B424 | Kentucky 236 | Iowa | S0504 | B960 | Rhode Island 265 | Arizona | SG516 | B190 | Vermont 296 | Rhode Island | SG527 B647 | Florida i I I 1 i i 114 rows

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions