Table of Contents

Introduction

Relational Schema for Computer Store Database

Load the Libraries

jupyter magic for postgres

Create Tables

We do in only once. Once we added these tables to our database dvdrental, we are done. We can now use these table now for all the future times.

Create pandas dataframes

Exercise Questions

Select the names of all the products in the store.

Question: 1. Select the names of all the products in the store.

Select the names and the prices of all the products in the store.

Question: 2. Select the names and the prices of all the products in the store.

Select the name of the products with a price less than or equal to 200.

Question: 3. Select the name of the products with a price less than or equal to $200.

Select all the products with a price between 60 and 120.

Question: 4. Select all the products with a price between \$60 and \$120.

Select the name and price in cents (i.e., the price must be multiplied by 100)

Question: 5. Select the name and price in cents (i.e., the price must be multiplied by 100)

Compute the average price of all the products.

Question: 6. Compute the average price of all the products.

Compute the average price of all products with manufacturer code equal to 2.

Question: 7. Compute the average price of all products with manufacturer code equal to 2.

Compute the number of products with a price larger than or equal to 180

Question: 8. Compute the number of products with a price larger than or equal to $180.

Select the name and price of all products with a price larger than or equal to 180, and sort first by price (in descending order), and then by name (in ascending order).

Question: 9. Select the name and price of all products with a price larger than or equal to $180, and sort first by price (in descending order), and then by name (in ascending order).

Select all the data from the products, including all the data for each product's manufacturer.

Question: 10. Select all the data from the products, including all the data for each product's manufacturer.

Select the product name, price, and manufacturer name of all the products.

Question: 11. Select the product name, price, and manufacturer name of all the products.

Select the average price of each manufacturer's products, showing only the manufacturer's code.

Question: 12. Select the average price of each manufacturer's products, showing only the manufacturer's code.

Select the average price of each manufacturer's products, showing the manufacturer's name.

Question: 13. Select the average price of each manufacturer's products, showing the manufacturer's name.

Select the names of manufacturer whose products have an average price larger than or equal to 150.

Question: 14. Select the names of manufacturer whose products have an average price larger than or equal to $150.

Select the name and price of the cheapest product.

Question: 15. Select the name and price of the cheapest product.

Select the name of each manufacturer along with the name and price of its most expensive product.

Question: 16. Select the name of each manufacturer along with the name and price of its most expensive product.

Add a new product: Loudspeakers, 70, manufacturer 2.

Question: 17 Add a new product: Loudspeakers, $70, manufacturer 2.

Update the name of product 8 to "Laser Printer".

Question: 18. Update the name of product 8 to "Laser Printer".

Apply a 10 percent discount to all products.

Question: 19. Apply a 10% discount to all products.

Apply a 10% discount to all products with a price larger than or equal to 120.

Question: 20. Apply a 10% discount to all products with a price larger than or equal to $120.

Time Taken