Skip to content
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
41 changes: 41 additions & 0 deletions Week1/databases/assigment/meetup.js
Original file line number Diff line number Diff line change
@@ -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 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")');
await connection.query('INSERT INTO Invitee VALUES (4, "Maria Ivanova", "Dmitry Sokolov")');
await connection.query('INSERT INTO Invitee VALUES (5, "Oleg Smirnov", "Maria Ivanova")');
Comment on lines +19 to +23

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add AUTO_INCREMENT for invitee_no then you don't need to specify 1,2,3,4,5 when inserting new invitees.


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();
39 changes: 39 additions & 0 deletions Week1/databases/assigment/world.js
Original file line number Diff line number Diff line change
@@ -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 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?
await connection.query('SELECT SUM(Population) FROM country');

} catch (error) {
console.error(error);
}

connection.end();