From bc4248fdbfc5aff1ac985fb87d69213cc3972ab7 Mon Sep 17 00:00:00 2001 From: Ilias Khugaev Date: Wed, 21 May 2025 15:41:19 +0200 Subject: [PATCH 1/2] solved assignment --- Week1/databases/assigment/meetup.js | 41 +++++++++++++++++++++++++++++ Week1/databases/assigment/world.js | 39 +++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 Week1/databases/assigment/meetup.js create mode 100644 Week1/databases/assigment/world.js diff --git a/Week1/databases/assigment/meetup.js b/Week1/databases/assigment/meetup.js new file mode 100644 index 000000000..df17b29ec --- /dev/null +++ b/Week1/databases/assigment/meetup.js @@ -0,0 +1,41 @@ +import mysql from 'mysql2/promise'; + +// Create the connection to database +const connection = await mysql.createConnection({ + host: 'localhost', + user: 'hyfuser', + password: 'hyfpassword' +}); + +connection.connect(); + +try { + await connection.query('CREATE DATABASE IF NOT EXISTS meetup'); + await connection.query('USE meetup'); + await connection.query('CREATE TABLE Invitee (invitee_no INT NOT NULL PRIMARY KEY, invitee_name VARCHAR(25) NOT NULL, invited_by VARCHAR(25))'); + await connection.query('CREATE TABLE Room (room_no INT NOT NULL PRIMARY KEY, room_name VARCHAR(25) NOT NULL, floor_number INT NOT NULL)'); + await connection.query('CREATE TABLE Meeting (meeting_no INT NOT NULL PRIMARY KEY, meeting_title VARCHAR(40) NOT NULL, staring_time DATETIME, ending_time DATETIME, room_no INT NOT NULL)'); + + await connection.query('INSERT INTO Invitee VALUES (1, "Ilias Khugaev", "Ilia Bubnov")'); + await connection.query('INSERT INTO Invitee VALUES (2, "Anna Petrova", "Ilias Khugaev")'); + await connection.query('INSERT INTO Invitee VALUES (3, "Dmitry Sokolov", "Anna Petrova")'); + await connection.query('INSERT INTO Invitee VALUES (4, "Maria Ivanova", "Dmitry Sokolov")'); + await connection.query('INSERT INTO Invitee VALUES (5, "Oleg Smirnov", "Maria Ivanova")'); + + await connection.query('INSERT INTO Room VALUES (1, "Orion", 1)'); + await connection.query('INSERT INTO Room VALUES (2, "Pegasus", 1)'); + await connection.query('INSERT INTO Room VALUES (3, "Centauri", 2)'); + await connection.query('INSERT INTO Room VALUES (4, "Andromeda", 2)'); + await connection.query('INSERT INTO Room VALUES (5, "Phoenix", 3)'); + + await connection.query('INSERT INTO Meeting VALUES (1, "Project Kickoff", "2025-05-21 09:00:00", "2025-05-21 10:00:00", 1)'); + await connection.query('INSERT INTO Meeting VALUES (2, "Design Review", "2025-05-21 10:30:00", "2025-05-21 11:30:00", 2)'); + await connection.query('INSERT INTO Meeting VALUES (3, "Sprint Planning", "2025-05-21 12:00:00", "2025-05-21 13:00:00", 3)'); + await connection.query('INSERT INTO Meeting VALUES (4, "Client Sync", "2025-05-21 14:00:00", "2025-05-21 15:00:00", 4)'); + await connection.query('INSERT INTO Meeting VALUES (5, "Retrospective", "2025-05-21 16:00:00", "2025-05-21 17:00:00", 5)'); + +} catch (error) { + console.log(error); +} + +connection.end(); \ No newline at end of file diff --git a/Week1/databases/assigment/world.js b/Week1/databases/assigment/world.js new file mode 100644 index 000000000..58a8b7af3 --- /dev/null +++ b/Week1/databases/assigment/world.js @@ -0,0 +1,39 @@ +import mysql from 'mysql2/promise'; + +// Create the connection to database +const connection = await mysql.createConnection({ + host: 'localhost', + user: 'hyfuser', + password: 'hyfpassword' +}); + +connection.connect(); + +try { + await connection.query('USE new_world'); +// What are the names of countries with population greater than 8 million + await connection.query('SELECT name FROM country WHERE population > 8000000'); +// What are the names of countries that have “land” in their names? + await connection.query('SELECT name FROM country WHERE name LIKE "%land%"'); +// What are the names of the cities with population in between 500,000 and 1 million? + await connection.query('SELECT name FROM city WHERE population BETWEEN 500000 AND 1000000'); +// What's the name of all the countries on the continent ‘Europe’? + await connection.query('SELECT name FROM country WHERE Continent = "Europe"'); +// List all the countries in the descending order of their surface areas. + await connection.query('SELECT name FROM country ORDER BY SurfaceArea DESC'); +// What are the names of all the cities in the Netherlands? + await connection.query('SELECT name FROM city WHERE CountryCode = "NLD"'); +// What is the population of Rotterdam? + await connection.query('SELECT name, Population FROM city WHERE name = "Rotterdam"'); +// What's the top 10 countries by Surface Area? + await connection.query('SELECT name FROM country ORDER BY SurfaceArea LIMIT DESC 10'); +// What's the top 10 most populated cities? + await connection.query('SELECT name, Population FROM city ORDER BY population DESC LIMIT 10'); +// What is the population number of the world? + await connection.query('SELECT SUM(Population) FROM country'); + +} catch (error) { + console.error(error); +} + +connection.end(); \ No newline at end of file From fbe5a411af9f6ddd33d658167e92f057c411f2bb Mon Sep 17 00:00:00 2001 From: Ilias Khugaev Date: Tue, 27 May 2025 12:29:21 +0200 Subject: [PATCH 2/2] fixes after rew --- Week1/databases/assigment/meetup.js | 16 +++++++-------- Week1/databases/assigment/world.js | 30 ++++++++++++++--------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Week1/databases/assigment/meetup.js b/Week1/databases/assigment/meetup.js index df17b29ec..e371533c3 100644 --- a/Week1/databases/assigment/meetup.js +++ b/Week1/databases/assigment/meetup.js @@ -2,9 +2,9 @@ import mysql from 'mysql2/promise'; // Create the connection to database const connection = await mysql.createConnection({ - host: 'localhost', - user: 'hyfuser', - password: 'hyfpassword' + host: 'localhost', + user: 'hyfuser', + password: 'hyfpassword' }); connection.connect(); @@ -12,10 +12,10 @@ connection.connect(); try { await connection.query('CREATE DATABASE IF NOT EXISTS meetup'); await connection.query('USE meetup'); - await connection.query('CREATE TABLE Invitee (invitee_no INT NOT NULL PRIMARY KEY, invitee_name VARCHAR(25) NOT NULL, invited_by VARCHAR(25))'); - await connection.query('CREATE TABLE Room (room_no INT NOT NULL PRIMARY KEY, room_name VARCHAR(25) NOT NULL, floor_number INT NOT NULL)'); - await connection.query('CREATE TABLE Meeting (meeting_no INT NOT NULL PRIMARY KEY, meeting_title VARCHAR(40) NOT NULL, staring_time DATETIME, ending_time DATETIME, room_no INT NOT NULL)'); - + await connection.query('CREATE TABLE Invitee (invitee_no INT PRIMARY KEY AUTO_INCREMENT, invitee_name VARCHAR(25) NOT NULL, invited_by VARCHAR(25))'); + await connection.query('CREATE TABLE Room (room_no INT PRIMARY KEY AUTO_INCREMENT, room_name VARCHAR(25) NOT NULL, floor_number TINYINT NOT NULL)'); + await connection.query('CREATE TABLE Meeting (meeting_no INT PRIMARY KEY AUTO_INCREMENT, meeting_title VARCHAR(40) NOT NULL, staring_time DATETIME, ending_time DATETIME, room_no INT NOT NULL)'); + await connection.query('INSERT INTO Invitee VALUES (1, "Ilias Khugaev", "Ilia Bubnov")'); await connection.query('INSERT INTO Invitee VALUES (2, "Anna Petrova", "Ilias Khugaev")'); await connection.query('INSERT INTO Invitee VALUES (3, "Dmitry Sokolov", "Anna Petrova")'); @@ -35,7 +35,7 @@ try { await connection.query('INSERT INTO Meeting VALUES (5, "Retrospective", "2025-05-21 16:00:00", "2025-05-21 17:00:00", 5)'); } catch (error) { - console.log(error); + console.log(error); } connection.end(); \ No newline at end of file diff --git a/Week1/databases/assigment/world.js b/Week1/databases/assigment/world.js index 58a8b7af3..b0388f1d6 100644 --- a/Week1/databases/assigment/world.js +++ b/Week1/databases/assigment/world.js @@ -2,36 +2,36 @@ import mysql from 'mysql2/promise'; // Create the connection to database const connection = await mysql.createConnection({ - host: 'localhost', - user: 'hyfuser', - password: 'hyfpassword' + host: 'localhost', + user: 'hyfuser', + password: 'hyfpassword' }); connection.connect(); try { await connection.query('USE new_world'); -// What are the names of countries with population greater than 8 million + // What are the names of countries with population greater than 8 million await connection.query('SELECT name FROM country WHERE population > 8000000'); -// What are the names of countries that have “land” in their names? + // What are the names of countries that have “land” in their names? await connection.query('SELECT name FROM country WHERE name LIKE "%land%"'); -// What are the names of the cities with population in between 500,000 and 1 million? + // What are the names of the cities with population in between 500,000 and 1 million? await connection.query('SELECT name FROM city WHERE population BETWEEN 500000 AND 1000000'); -// What's the name of all the countries on the continent ‘Europe’? + // What's the name of all the countries on the continent ‘Europe’? await connection.query('SELECT name FROM country WHERE Continent = "Europe"'); -// List all the countries in the descending order of their surface areas. + // List all the countries in the descending order of their surface areas. await connection.query('SELECT name FROM country ORDER BY SurfaceArea DESC'); -// What are the names of all the cities in the Netherlands? + // What are the names of all the cities in the Netherlands? await connection.query('SELECT name FROM city WHERE CountryCode = "NLD"'); -// What is the population of Rotterdam? + // What is the population of Rotterdam? await connection.query('SELECT name, Population FROM city WHERE name = "Rotterdam"'); -// What's the top 10 countries by Surface Area? - await connection.query('SELECT name FROM country ORDER BY SurfaceArea LIMIT DESC 10'); -// What's the top 10 most populated cities? + // What's the top 10 countries by Surface Area? + await connection.query('SELECT name FROM country ORDER BY SurfaceArea DESC LIMIT 10'); + // What's the top 10 most populated cities? await connection.query('SELECT name, Population FROM city ORDER BY population DESC LIMIT 10'); -// What is the population number of the world? + // What is the population number of the world? await connection.query('SELECT SUM(Population) FROM country'); - + } catch (error) { console.error(error); }