Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node week3/andrii p #226

Open
wants to merge 5 commits into
base: main
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
144 changes: 144 additions & 0 deletions databases/week3/hw3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
CREATE DATABASE hw3_meal

USE hw3_meal;

CREATE TABLE meal (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(100) NOT NULL,
`description` TEXT,
`location` VARCHAR(255) NOT NULL,
`when` DATETIME NOT NULL,
`max_reservations` INT UNSIGNED NOT NULL,
`price` DECIMAL(10,2),
`created_date` DATE NOT NULL
);

CREATE TABLE `reservation` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`number_of_guests` INT UNSIGNED NOT NULL,
`meal_id` INT(10) UNSIGNED NOT NULL,
`created_date` DATE NOT NULL,
`contact_phonenumber` VARCHAR(100) NOT NULL,
`contact_name` VARCHAR(100) NOT NULL,
`contact_email` VARCHAR(100) NOT NULL,
FOREIGN KEY (`meal_id`) REFERENCES `meal`(`id`) ON DELETE CASCADE
);

CREATE TABLE `review` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` VARCHAR(100) NOT NULL,
`description` TEXT,
`meal_id` INT(10) UNSIGNED NOT NULL,
`stars` INT(5) NOT NULL,
`created_date` DATE NOT NULL,
FOREIGN KEY (`meal_id`) REFERENCES `meal`(`id`) ON DELETE CASCADE
)


-- QUERIES

-- Meal

SELECT *
FROM meal;

INSERT INTO meal (title, description, location, `when`, max_reservations, price, created_date)
VALUES ('Traditonal Sicilian Pasta Carbonara', 'Master class from of cooking Carbonara from the best sicilain chef.', 'Palermo, IT', '2025-05-09', 25, 34.99, '2025-02-17');

INSERT INTO meal (title, description, location, `when`, max_reservations, price, created_date)
VALUES ('10 Different ways to make a great pizza', 'Very good mini-course of making real italian pizza', 'Rome, IT', '2025-04-23', 20, 24.00, '2025-02-19');

SELECT *
FROM meal
WHERE id = 2;

UPDATE meal
SET location = 'Napoli, IT',
price = 29.95
WHERE id = 2;

DELETE FROM meal
WHERE id = 1

-- Reservation

SELECT *
FROM reservation

INSERT INTO `reservation` (`number_of_guests`, `meal_id`, `created_date`, `contact_phonenumber`, `contact_name`, `contact_email`)
VALUES (4, 2, CURDATE(), '52 45 12 34', 'Pedro Moretti', '[email protected]');

SELECT * FROM `reservation` WHERE `id` = 2;

UPDATE `reservation`
SET `number_of_guests` = 10
WHERE `id` = 2;

UPDATE `reservation`
SET `number_of_guests` = 7,
`contact_name` = 'Anna-Maria Moretti',
`contact_email` = '[email protected]'
WHERE `id` = 2;

DELETE FROM reservation
WHERE id = 2

-- Review

SELECT * FROM `review`;

INSERT INTO `review` (`title`, `description`, `meal_id`, `stars`, `created_date`)
VALUES ('Great meal!', 'It was very, very tasty and the service was TOP!', 2, 5, CURDATE());

SELECT * FROM review
WHERE id = 1

UPDATE `review`
SET `description` = 'Et kæmpe stort TAK til alle, der lavede den lækker mad!',
`title` = 'Super!!'
WHERE `id` = 1;

DELETE FROM review
WHERE id = 2

-- Additional queries

SELECT * FROM meal
WHERE price >= 90;

SELECT m.*
FROM meal m
LEFT JOIN (
SELECT meal_id, SUM(number_of_guests) AS total_reserved
FROM reservation
GROUP BY meal_id
) r ON m.id = r.meal_id
WHERE r.total_reserved IS NULL OR r.total_reserved < m.max_reservations;


SELECT * FROM `meal`
WHERE `title` LIKE '%Rød grød med%';


SELECT * FROM `meal`
WHERE `created_date` BETWEEN '2025-01-01' AND '2026-02-01';


SELECT * FROM `meal`
LIMIT 5;


SELECT DISTINCT *
FROM meal m
JOIN review r ON m.id = r.meal_id
WHERE r.stars >= 4;

SELECT * FROM `reservation`
WHERE `meal_id` = 2
ORDER BY `created_date` DESC;

SELECT m.*, AVG(r.stars) AS avg_stars
FROM `meal` m
LEFT JOIN `review` r ON m.id = r.meal_id
GROUP BY m.id
ORDER BY avg_stars DESC;
62 changes: 62 additions & 0 deletions javascript/javascript1/week1/homework_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--1. Find out how many tasks are in the task table

SELECT COUNT (*)
FROM task

--2. Find out how many tasks in the task table do not have a valid due date

SELECT COUNT (*)
FROM task
WHERE due_date IS NULL

--3. Find all the tasks that are marked as done

SELECT task.title, status.name
FROM task JOIN status ON task.status_id = status.id
WHERE status.name IN ('Done')

--4. Find all the tasks that are not marked as done

SELECT task.title, status.name
FROM task JOIN status ON task.status_id = status.id
WHERE status.name NOT IN ('Done')

--5. Get all the tasks, sorted with the most recently created first

SELECT *
FROM task
ORDER BY created

--6. Get the single most recently created task

SELECT *
FROM task
ORDER BY created
LIMIT 1

--7. Get the title and due date of all tasks where the title or description contains database

SELECT task.title, task.due_date
FROM task
WHERE task.title LIKE '%database%'
OR task.description LIKE '%database%';

--8. Get the title and status (as text) of all tasks

SELECT task.title, status.name
FROM task JOIN status ON task.status_id = status.id

--9. Get the name of each status, along with a count of how many tasks have that status

SELECT status.name, COUNT(task.id)
FROM status
LEFT JOIN task ON status.id = task.status_id
GROUP BY status.name;

--10. Get the names of all statuses, sorted by the status with most tasks first

SELECT status.name, COUNT(task.id) AS task_count
FROM status
LEFT JOIN task ON status.id = task.status_id
GROUP BY status.name
ORDER BY task_count DESC
78 changes: 78 additions & 0 deletions javascript/javascript1/week2/HW2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
-- Part 1: Working with tasks

USE hw

INSERT INTO task (title, description, created, updated, due_date, status_id, user_id)
VALUES ('Do your homework', 'You need to complete your homework, consists of 4 parts', '2025-02-09', '2025-02-11', '2025-02-16', 2, 5 );

UPDATE task
SET title = 'Do your hw and class preparation',
due_date = '2025-02-14 22:30:00',
status_id = 3
WHERE id = 36

DELETE FROM task
WHERE id = 36

SELECT * FROM task

-- Part 2: School database

USE DB_HW2

CREATE TABLE `class` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`begins` DATETIME NOT NULL,
`ends` DATETIME NULL
);

CREATE TABLE `student` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR (255) NOT NULL,
`email` VARCHAR(255) NULL,
`phone` VARCHAR(255) NULL,
`class_id` int(10) UNSIGNED NOT NULL,
CONSTRAINT `fk_class` FOREIGN KEY (`class_id`) REFERENCES `class` (`id`)
);

CREATE INDEX idx_student_name
ON student (name);

ALTER TABLE class
ADD status ENUM('not-started', 'ongoing', 'finished') NOT NULL

-- Part 3: More queries

USE hw

SELECT *
FROM task
JOIN user_task ON task.id = user_task.task_id
JOIN user ON user_task.user_id = user.id
WHERE user.email LIKE '%@spotify.com';

SELECT *
FROM task
JOIN user_task ON task.id = user_task.task_id
JOIN user ON user_task.user_id = user.id
JOIN status ON task.status_id = status_id
WHERE user.name = 'Donald Duck'
AND status.name = 'Not started';

SELECT *
FROM task
JOIN user_task ON task.id = user_task.task_id
JOIN user ON user_task.user_id = user.id
JOIN status ON task.status_id = status_id
WHERE user.name = 'Maryrose Meadows'
AND MONTH(created) = 9

SELECT MONTH(created) AS month_number, COUNT(*) AS task_count
FROM task
GROUP BY MONTH(created)
ORDER BY month_number;


-- Part 4: Creating a database

Binary file added javascript/javascript1/week2/factory_db.pdf
Binary file not shown.
72 changes: 72 additions & 0 deletions javascript/javascript1/week2/task4CreatingDB.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
CREATE DATABASE `factory_db`
DEFAULT CHARACTER SET = 'utf8mb4';

USE factory_db;

CREATE TABLE `departments` (
`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR (50) NOT NULL
);

INSERT INTO departments (name)
VALUES ('Compact'), ('Maxi'), ('Lager');

CREATE TABLE `duties` (
`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`duty_name` VARCHAR(50) NOT NULL UNIQUE,
`description` TEXT
);

INSERT INTO duties (duty_name, description) VALUES
('Quality Control', 'Inspect products for defects'),
('Employee Hiring', 'Find more employees'),
('Inventory Management', 'Monitor stock levels');

CREATE TABLE `shifts` (
`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`shift_name` ENUM('morning', 'afternoon', 'night')
);

INSERT INTO shifts (shift_name)
VALUES ('morning'), ('afternoon'), ('night');

CREATE TABLE `staff` (
`id` INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`depart_id` INT UNSIGNED NOT NULL,
`shift_id` INT UNSIGNED NOT NULL,
FOREIGN KEY(`depart_id`) REFERENCES `departments` (`id`) ON DELETE CASCADE,
FOREIGN KEY(`shift_id`) REFERENCES `shifts` (`id`) ON DELETE CASCADE
);

INSERT INTO staff (name, depart_id, shift_id) VALUES
('Jens Jakobsen', 1, 2),
('Andrii Pavliuk', 2, 3),
('Lene Vestergaard', 3, 1);

CREATE TABLE staff_duties (
staff_id INT UNSIGNED,
duty_id INT UNSIGNED,
created DATETIME NOT NULL,
PRIMARY KEY (staff_id, duty_id),
FOREIGN KEY (staff_id) REFERENCES staff(id) ON DELETE CASCADE,
FOREIGN KEY (duty_id) REFERENCES duties(id) ON DELETE CASCADE
);

INSERT INTO staff_duties (staff_id, duty_id, created) VALUES
(1, 1, '2025-02-13'),
(2, 2, '2025-02-14'),
(3, 3, '2025-02-15');

SELECT staff.name AS Employee, staff_duties.created, duties.duty_name, duties.description
FROM staff
JOIN staff_duties ON staff.id = staff_duties.staff_id
JOIN duties ON staff_duties.duty_id = duties.id;

SELECT
staff.name AS Employee,
departments.name AS Department,
shifts.shift_name AS Shift
FROM staff
JOIN departments ON staff.depart_id = departments.id
JOIN shifts ON staff.shift_id = shifts.id;
12 changes: 12 additions & 0 deletions nodejs/week2/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions nodejs/week2/node_modules/.bin/mime.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading