From e0d2a784d7d4fed8ab92cebe5853e186581ac4eb Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 11 Mar 2024 13:31:05 +0100 Subject: [PATCH] 'Excercises for SQL and html;' --- 03_Sql_html/html_excercise.txt | 1 + 03_Sql_html/schema.sql | 35 ++++++++++++++++++++++++++++++++++ 03_Sql_html/sql_excercises.txt | 22 +++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 03_Sql_html/html_excercise.txt create mode 100644 03_Sql_html/schema.sql create mode 100644 03_Sql_html/sql_excercises.txt diff --git a/03_Sql_html/html_excercise.txt b/03_Sql_html/html_excercise.txt new file mode 100644 index 0000000..92d42fe --- /dev/null +++ b/03_Sql_html/html_excercise.txt @@ -0,0 +1 @@ +Create html view, in plain text, for some of the SQl results. \ No newline at end of file diff --git a/03_Sql_html/schema.sql b/03_Sql_html/schema.sql new file mode 100644 index 0000000..226069f --- /dev/null +++ b/03_Sql_html/schema.sql @@ -0,0 +1,35 @@ +-- The Warehouse +-- lINK: https://en.wikibooks.org/wiki/SQL_Exercises/The_warehouse + +CREATE TABLE Warehouses ( + Code INTEGER NOT NULL, + Location VARCHAR(255) NOT NULL , + Capacity INTEGER NOT NULL, + PRIMARY KEY (Code) + ); +CREATE TABLE Boxes ( + Code CHAR(4) NOT NULL, + Contents VARCHAR(255) NOT NULL , + Value REAL NOT NULL , + Warehouse INTEGER NOT NULL, + PRIMARY KEY (Code), + FOREIGN KEY (Warehouse) REFERENCES Warehouses(Code) + ) ENGINE=INNODB; + + INSERT INTO Warehouses(Code,Location,Capacity) VALUES(1,'Chicago',3); + INSERT INTO Warehouses(Code,Location,Capacity) VALUES(2,'Chicago',4); + INSERT INTO Warehouses(Code,Location,Capacity) VALUES(3,'New York',7); + INSERT INTO Warehouses(Code,Location,Capacity) VALUES(4,'Los Angeles',2); + INSERT INTO Warehouses(Code,Location,Capacity) VALUES(5,'San Francisco',8); + + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('0MN7','Rocks',180,3); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('4H8P','Rocks',250,1); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('4RT3','Scissors',190,4); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('7G3H','Rocks',200,1); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('8JN6','Papers',75,1); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('8Y6U','Papers',50,3); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('9J6F','Papers',175,2); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('LL08','Rocks',140,4); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('P0H6','Scissors',125,1); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('P2T6','Scissors',150,2); + INSERT INTO Boxes(Code,Contents,Value,Warehouse) VALUES('TU55','Papers',90,5); \ No newline at end of file diff --git a/03_Sql_html/sql_excercises.txt b/03_Sql_html/sql_excercises.txt new file mode 100644 index 0000000..e05d638 --- /dev/null +++ b/03_Sql_html/sql_excercises.txt @@ -0,0 +1,22 @@ +--3.1 Select all warehouses. +--3.2 Select all boxes with a value larger than $150. +--3.3 Select all distinct contents in all the boxes. +--3.4 Select the average value of all the boxes. +--3.5 Select the warehouse code and the average value of the boxes in each warehouse. +--3.6 Same as previous exercise, but select only those warehouses where the average value of the boxes is greater than 150. +--3.7 Select the code of each box, along with the name of the city the box is located in. +--3.8 Select the warehouse codes, along with the number of boxes in each warehouse. + -- Optionally, take into account that some warehouses are empty (i.e., the box count should show up as zero, instead of omitting the warehouse from the result). +--3.9 Select the codes of all warehouses that are saturated (a warehouse is saturated if the number of boxes in it is larger than the warehouse's capacity). +--3.10 Select the codes of all the boxes located in Chicago. +--3.11 Create a new warehouse in New York with a capacity for 3 boxes. +--3.12 Create a new box, with code "H5RT", containing "Papers" with a value of $200, and located in warehouse 2. +--3.13 Reduce the value of all boxes by 15%. +--3.14 Remove all boxes with a value lower than $100. +-- 3.15 Remove all boxes from saturated warehouses. +-- 3.16 Add Index for column "Warehouse" in table "boxes" + -- !!!NOTE!!!: index should NOT be used on small tables in practice +-- 3.17 Print all the existing indexes + -- !!!NOTE!!!: index should NOT be used on small tables in practice +-- 3.18 Remove (drop) the index you added just + -- !!!NOTE!!!: index should NOT be used on small tables in practice \ No newline at end of file