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

Databases week3/soheib #225

Open
wants to merge 3 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions databases/week3/data_enty.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- Insert data into meal table
INSERT INTO meal (title, description, location, `when`, max_reservations, price, created_date) VALUES
('Italian Pasta Night', 'Delicious homemade pasta with authentic Italian flavors.', 'Copenhagen', '2025-03-15', 10, 12.99, '2025-02-25'),
('Sushi Extravaganza', 'A night of fresh sushi and sashimi.', 'Aarhus', '2025-03-18', 8, 25.50, '2025-02-26'),
('Vegan Delight', 'A full-course vegan meal with organic ingredients.', 'Odense', '2025-03-20', 12, 18.75, '2025-02-27'),
('BBQ Feast', 'Slow-cooked BBQ meats with homemade sauces.', 'Aalborg', '2025-03-22', 15, 22.00, '2025-02-28'),
('Mexican Fiesta', 'Spicy and flavorful Mexican dishes.', 'Esbjerg', '2025-03-25', 10, 14.99, '2025-02-28'),
('Seafood Lovers', 'Fresh seafood straight from the coast.', 'Copenhagen', '2025-03-28', 6, 30.00, '2025-03-01'),
('French Cuisine Night', 'Classic French dishes paired with wine.', 'Aarhus', '2025-04-01', 10, 35.50, '2025-03-02'),
('Indian Curry Fest', 'A variety of authentic Indian curries.', 'Odense', '2025-04-03', 12, 16.50, '2025-03-03'),
('Burger Bonanza', 'Gourmet burgers with hand-cut fries.', 'Aalborg', '2025-04-06', 15, 13.99, '2025-03-04'),
('Taco Tuesday', 'All-you-can-eat tacos with fresh toppings.', 'Esbjerg', '2025-04-09', 20, 10.99, '2025-03-05'),
('Mediterranean Delights', 'A healthy and flavorful Mediterranean meal.', 'Copenhagen', '2025-04-12', 8, 19.99, '2025-03-06'),
('Korean BBQ Night', 'Grilled meats and classic Korean sides.', 'Aarhus', '2025-04-15', 10, 28.00, '2025-03-07'),
('Pizza Party', 'Wood-fired pizzas with fresh toppings.', 'Odense', '2025-04-18', 12, 15.50, '2025-03-08'),
('Steakhouse Special', 'Premium cuts of beef grilled to perfection.', 'Aalborg', '2025-04-21', 8, 40.00, '2025-03-09'),
('Greek Night', 'Greek dishes with fresh tzatziki and feta cheese.', 'Esbjerg', '2025-04-24', 10, 17.50, '2025-03-10'),
('Dim Sum Brunch', 'Traditional Chinese dumplings and buns.', 'Copenhagen', '2025-04-27', 10, 21.00, '2025-03-11'),
('Middle Eastern Feast', 'A mix of kebabs, hummus, and more.', 'Aarhus', '2025-04-30', 12, 23.50, '2025-03-12'),
('American Diner Experience', 'Classic American comfort food.', 'Odense', '2025-05-03', 15, 14.00, '2025-03-13'),
('Fusion Food Night', 'A mix of global flavors in one meal.', 'Aalborg', '2025-05-06', 10, 26.75, '2025-03-14'),
('Healthy Bowls', 'Nutrient-packed grain bowls with fresh ingredients.', 'Esbjerg', '2025-05-09', 12, 13.50, '2025-03-15');

-- Insert data into reservation table
INSERT INTO reservation (number_of_guests, meal_id, created_date, contact_phone_number, contact_name, contact_email) VALUES
(2, 1, '2025-03-01', '12345678', 'Alice Johnson', '[email protected]'),
(3, 2, '2025-03-02', '23456789', 'Bob Smith', '[email protected]'),
(1, 3, '2025-03-03', '34567890', 'Charlie Brown', '[email protected]'),
(4, 4, '2025-03-04', '45678901', 'David Lee', '[email protected]'),
(2, 5, '2025-03-05', '56789012', 'Eve Adams', '[email protected]'),
(5, 6, '2025-03-06', '67890123', 'Frank Miller', '[email protected]'),
(3, 7, '2025-03-07', '78901234', 'Grace Kelly', '[email protected]'),
(1, 8, '2025-03-08', '89012345', 'Hank Green', '[email protected]'),
(2, 9, '2025-03-09', '90123456', 'Ivy Wilson', '[email protected]'),
(4, 10, '2025-03-10', '12340987', 'Jack White', '[email protected]');

-- Insert data into review table
INSERT INTO review (title, description, meal_id, stars, created_date) VALUES
('Amazing Pasta', 'The best Italian pasta I’ve had in years!', 1, 5, '2025-03-16'),
('Sushi Heaven', 'Super fresh sushi, highly recommend!', 2, 5, '2025-03-19'),
('Great Vegan Options', 'Loved the variety of vegan dishes.', 3, 4, '2025-03-21'),
('Best BBQ Ever', 'The ribs were falling off the bone.', 4, 5, '2025-03-23'),
('Spicy and Delicious', 'Authentic Mexican flavors!', 5, 4, '2025-03-26'),
('So Fresh!', 'Amazing seafood, great atmosphere.', 6, 5, '2025-03-29'),
('French Elegance', 'A true taste of France.', 7, 5, '2025-04-02'),
('Perfectly Spiced', 'Best curry in town.', 8, 4, '2025-04-04'),
('Burger Bliss', 'Juicy and flavorful burgers.', 9, 5, '2025-04-07'),
('Taco Overload', 'So many tacos, all were delicious.', 10, 4, '2025-04-10');
37 changes: 37 additions & 0 deletions databases/week3/mealsharing_create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CREATE DATABASE mealsharing_db
DEFAULT CHARACTER SET = 'utf8mb4';

USE mealsharing_db;

CREATE TABLE meal (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255),
description TEXT,
location VARCHAR(255),
`when` DATE,
max_reservations INT,
price DECIMAL(5, 2),
created_date DATE
);


CREATE TABLE reservation (
id INT PRIMARY KEY AUTO_INCREMENT,
number_of_guests INT,
meal_id INT,
created_date DATE,
contact_phone_number VARCHAR(255),
contact_name VARCHAR(255),
contact_email VARCHAR(255),
FOREIGN KEY (meal_id) REFERENCES meal(id) ON DELETE CASCADE
);

CREATE TABLE review (
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255),
description TEXT,
meal_id INT,
stars INT,
created_date DATE,
FOREIGN KEY (meal_id) REFERENCES meal(id) ON DELETE CASCADE
);
78 changes: 78 additions & 0 deletions databases/week3/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
--Get all meals
--Get all meals
SELECT * FROM meal;

--Add a new meal
INSERT INTO meal (title, description, location, `when`, max_reservations, price, created_date) VALUES ('Burak', 'Deep fried crunchy rolls, soft and creamy inside', 'Aalborg', '2025-03-18', 4, 25.50, '2025-02-26');

SELECT * FROM meal WHERE id = 10;

-- update a meal
UPDATE meal SET title = 'Brik' WHERE id = 21;

-- delete a meal
DELETE FROM meal WHERE id = 1;

-- Get all reservations
SELECT * FROM reservation;

-- Add a new reservation
INSERT INTO reservation (number_of_guests, meal_id, created_date, contact_phone_number, contact_name, contact_email) VALUES (7, 10, '2025-03-01', '12345678', 'Juan Cruz', '[email protected]');

-- get a reservation with an id
SELECT * FROM reservation WHERE id = 5;

-- update a reservation
UPDATE reservation SET number_of_guests = 8 WHERE id = 5;

-- delete a reservation
DELETE FROM reservation WHERE id = 5;

-- Get all reviews
SELECT * FROM review;

-- Add a new review
INSERT INTO review (title, description, meal_id, stars, created_date) VALUES ('Best Burak', 'The best Burak I’ve had in years!', 10, 5, '2025-03-16');

-- get a review with an id
SELECT * FROM review WHERE id = 5;

-- update a review
UPDATE review SET title = 'Best Brik' WHERE id = 5;

-- delete a review
DELETE FROM review WHERE id = 5;

-- getting all meals cheaper than 15
SELECT * FROM meal WHERE price < 15;

-- all meals with available reservations
SELECT meal.*
FROM meal
LEFT JOIN reservation ON meal.id = reservation.meal_id
WHERE meal.max_reservations > (
SELECT COUNT(*) FROM reservation WHERE reservation.meal_id = meal.id
);
-- Get meals that partially match a title
SELECT * FROM meal WHERE title LIKE '%BBQ%';

--Get meals that has been created between two dates
SELECT * FROM meal WHERE created_date BETWEEN '2025-03-01' AND '2025-03-5';

--Get only specific number of meals fx return only 5 meals
SELECT * FROM meal LIMIT 5;

--Get the meals that have good reviews
SELECT * FROM meal
JOIN review ON meal.id = review.meal_id
WHERE review.stars > 4;

--Get reservations for a specific meal sorted by created_date
SELECT * FROM reservation WHERE meal_id = 10 ORDER BY created_date;

--Sort all meals by average number of stars in the reviews
SELECT m.id, m.title, AVG(review.stars) AS avg_stars
FROM meal AS m
LEFT JOIN review ON m.id = review.meal_id
GROUP BY m.id
ORDER BY avg_stars DESC;