Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

HadiyahL/week3 #61

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions week-1/mandatory/2-classes-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,76 @@ Below you will find a set of tasks for you to complete to set up a databases of
To submit this homework write the correct commands for each question here:

```sql
1. createdb cyf_classes;

2. CREATE TABLE mentors (
id SERIAL PRIMARY KEY,
name VARCHAR(30) NOT NULL,
years INT,
address VARCHAR(120),
prog_language VARCHAR(20) NOT NULL
);

3. INSERT INTO mentors (name, years, address, prog_language) VALUES('Shukri Ali', 5, 'West Midlands, Glassgow', 'Java');
INSERT INTO mentors (name, years, address, prog_language) VALUES('Nadir Khan', 3, 'East Midlands, Glassgow', 'JavaScript');
INSERT INTO mentors (name, years, address, prog_language) VALUES('Emile Paffard-Wray', 10, 'South Midlands, Glasgow', 'React');
INSERT INTO mentors (name, years, address, prog_language) VALUES('Wahab Rehman', 8, 'North Midlands, Glasgow', 'React');
INSERT INTO mentors (name, years, address, prog_language) VALUES('Mark Farmiloe', 15, 'Great Midlands, Glassgow', 'SQL');

4. CREATE TABLE students (
id SERIAL PRIMARY KEY,
name VARCHAR(30) NOT NULL,
address VARCHAR(120),
graduate BOOLEAN NOT NULL
);

5. INSERT INTO students (name, address, graduate) VALUES('Hadiyah Lawal', 'West Midlands, Birmingham', false);
INSERT INTO students (name, address, graduate) VALUES('Sonjide Hussain', 'Clarkson, London', true);
INSERT INTO students (name, address, graduate) VALUES('Omolola Bello', 'Smethwick, Birmingham', false);
INSERT INTO students (name, address, graduate) VALUES('Cynthia Eburu', 'Chaltam House, London', true);
INSERT INTO students (name, address, graduate) VALUES('Min ko', 'Cape Town, South-Africa', true);
INSERT INTO students (name, address, graduate) VALUES('Zubeda Khanum', 'Green Lane, Birmingham', false);
INSERT INTO students (name, address, graduate) VALUES('Adebola Alaba-Ige', 'Coventry, Birmingham', false);
INSERT INTO students (name, address, graduate) VALUES('Gintaras Stankus', 'Solihull Quarters, Birmingham', false);
INSERT INTO students (name, address, graduate) VALUES('Ellie Tahmasebi', 'Alexandra Avenue, London', true);
INSERT INTO students (name, address, graduate) VALUES('Denis Peptanariu', 'Egbaston Avenue, Birmingham', false);

6. SELECT * FROM mentors;
SELECT * FROM students;

7. CREATE TABLE classes (
id SERIAL PRIMARY KEY,
leading_mentor VARCHAR(30) NOT NULL,
module VARCHAR(30) NOT NULL,
location VARCHAR(30) NOT NULL,
date DATE NOT NULL
);

8. INSERT INTO classes (leading_mentor, module, location, date) VALUES('Cemil Okay', 'HTML/CSS', 'Aston University, Birmingham', '2020-04-25');
INSERT INTO classes (leading_mentor, module, location, date) VALUES('Wahab Rehman', 'JavaScript', 'Zoom Online class', '2020-05-28');
INSERT INTO classes (leading_mentor, module, location, date) VALUES('Andy Delaney', 'React', 'Zoom Online class', '2020-06-30');
INSERT INTO classes (leading_mentor, module, location, date) VALUES('Nick Holdsworth', 'Node.js', 'Zoom Online class', '2020-07-31');
INSERT INTO classes (leading_mentor, module, location, date) VALUES('Mark Farmiloe', 'SQL', 'Zoom Online class', '2020-09-02');

9. CREATE TABLE javascript (
id SERIAL PRIMARY KEY,
student_id INT REFERENCES students(id),
class_id INT REFERENCES classes(id)
);

INSERT INTO javascript (student_id, class_id) VALUES (3, 2);
INSERT INTO javascript (student_id, class_id) VALUES (4, 2);
INSERT INTO javascript (student_id, class_id) VALUES (6, 2);
INSERT INTO javascript (student_id, class_id) VALUES (7, 2);
INSERT INTO javascript (student_id, class_id) VALUES (9, 2);
INSERT INTO javascript (student_id, class_id) VALUES (10, 2);


10. SELECT * FROM mentors WHERE years > 5;
SELECT * FROM mentors WHERE prog_language = 'JavaScript';
SELECT * FROM students WHERE graduate = true;
SELECT * FROM classes WHERE date < '2020/06/01';
SELECT stu.name, stu.id, cla.leading_mentor FROM students stu,classes cla, javascript jav WHERE stu.id = student_id AND cla.id =class_id;
```

When you have finished all of the questions - open a pull request with your answers to the `Databases-Homework` repository.
Expand Down
26 changes: 23 additions & 3 deletions week-2/mandatory/2-ecommerce-db/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,31 @@ In this homework, you are going to work with an ecommerce database. In this data

Below you will find a set of tasks for you to complete to set up a databases of students and mentors.

To submit this homework write the correct commands for each question here:
To submit this homework write the correct commands for each question here: 11. Retrieve all the products with their supplier for all orders of all customers. The result should only contain the columns `name` (from customer), `order_reference` `order_date`, `product_name`, `supplier_name` and `quantity`. 12. Retrieve the names of all customers who bought a product from a supplier from China.

```sql


1. SELECT name, address FROM customers WHERE country = 'United States';
2. SELECT * FROM customers ORDER BY name;
3. SELECT * FROM products WHERE unit_price > 100;
4. SELECT * FROM products WHERE product_name LIKE '%socks%';
5. SELECT * FROM products ORDER BY unit_price DESC LIMIT 5;
6. SELECT p.product_name, s.supplier_name FROM products p, suppliers s WHERE s.id = p.supplier_id;
7. SELECT p.product_name, s.supplier_name, s.country FROM products p, suppliers s WHERE s.id = p.supplier_id
AND s.country = 'United Kingdom';
8. SELECT * FROM orders WHERE customer_id = 1;
9. SELECT * FROM orders o, customers c WHERE c.id = o.customer_id AND c.name = 'Hope Crosby';
10. SELECT p.product_name,p.unit_price,oi.quantity
FROM products p, orders o, order_items oi
WHERE p.id=oi.product_id
AND o.id=oi.order_id
AND o.order_reference = 'ORD006';
11. SELECT c.name, o.order_reference, o.order_date,p.product_name,s.supplier_name,oi.quantity
FROM customers c, products p, suppliers s, orders o, order_items oi
WHERE c.id=o.customer_id AND o.id=oi.order_id AND oi.product_id=p.id AND s.id=p.supplier_id;
12. SELECT c.name, p.product_name, s.country
FROM customers c, orders o, products p, suppliers s,order_items oi
WHERE c.id=o.customer_id AND o.id=oi.order_id AND oi.product_id=p.id AND s.id=p.supplier_id
AND s.country='China';
```

When you have finished all of the questions - open a pull request with your answers to the `Databases-Homework` repository.
Expand Down
1 change: 1 addition & 0 deletions week-2/mandatory/3-api/cyf-ecommerce-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Loading