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

Ruba-week1-dataBases #4

Open
wants to merge 1 commit 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
70 changes: 70 additions & 0 deletions Week1/Assignment/meetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { createConnection } from 'mysql2/promise';

const connection = await createConnection({
host: 'localhost',
user: 'hyfuser',
password: 'hyfpassword',
});

const drop_database_query = `DROP DATABASE IF EXISTS meetup`;
const create_database_query = `CREATE DATABASE meetup`;
const use_database_query = `USE meetup`;

const create_Invitee_query = `CREATE TABLE IF NOT EXISTS Invitee(
invitee_no INT AUTO_INCREMENT PRIMARY KEY,
invitee_name VARCHAR(255) NOT NULL,
invited_by VARCHAR(255) NOT NULL
)`;

const create_Room_query = `CREATE TABLE IF NOT EXISTS Room(
room_no INT AUTO_INCREMENT PRIMARY KEY,
room_name VARCHAR(255) NOT NULL,
floor_number INT NOT NULL
)`;

const create_Meeting_query = `CREATE TABLE IF NOT EXISTS Meeting(
meeting_no INT AUTO_INCREMENT PRIMARY KEY,
meeting_title VARCHAR(255) NOT NULL,
starting_time DATETIME NOT NULL,
ending_time DATETIME NOT NULL,
room_no INT,
FOREIGN KEY (room_no) REFERENCES Room(room_no)
)`;

const insert_Invitee_query= `
INSERT INTO Invitee (invitee_name, invited_by) VALUES
('Ali', 'Bob'),
('Ahmed', 'Ali'),
('David', 'Ahmed'),
('Salvatore','David'),
('Frank', 'Emma')`;

const insert_Room_query = `
INSERT INTO Room (room_name, floor_number) VALUES
('Conference Room A', 1),
('Conference Room B', 2),
('Main Hall', 1),
('Meeting Room 1', 3),
('Meeting Room 2', 3)`;

const insert_Meeting_query = `
INSERT INTO Meeting (meeting_title, starting_time, ending_time, room_no) VALUES
('Project Kickoff', '2024-12-17 09:00:00', '2024-12-17 10:30:00', 1),
('Team Standup', '2024-12-17 11:00:00', '2024-12-17 11:30:00', 2),
('Budget Planning', '2024-12-17 13:00:00', '2024-12-17 14:30:00', 3),
('Strategy Meeting', '2024-12-17 15:00:00', '2024-12-17 16:30:00', 4),
('Client Presentation', '2024-12-18 10:00:00', '2024-12-18 11:30:00', 5)`;

await connection.query(drop_database_query);
await connection.query(create_database_query);
await connection.query(use_database_query);

await connection.query(create_Invitee_query);
await connection.query(create_Room_query);
await connection.query(create_Meeting_query);

await connection.query(insert_Invitee_query);
await connection.query(insert_Room_query);
await connection.query(insert_Meeting_query);

connection.end();
66 changes: 66 additions & 0 deletions Week1/Assignment/world_query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { createConnection } from 'mysql2/promise';

const connection = await createConnection({
host: 'localhost',
user: 'hyfuser',
password: 'hyfpassword',
database: 'world',
});


try {
const select_population_query = `SELECT name FROM country WHERE population > 8000000`;
const [query1] = await connection.query(select_population_query);
console.log('Countries with population greater than 8 million:');
console.log(query1);

const select_land_query = `SELECT name FROM country WHERE name LIKE "%land%"`;
const [query2] = await connection.query(select_land_query);
console.log('Countries with "land" in their names:');
console.log(query2);

const select_city_query = `SELECT name FROM city WHERE population BETWEEN 500000 AND 1000000`;
const [query3] = await connection.query(select_city_query);
console.log('Cities with population between 500,000 and 1 million:');
console.log(query3);

const select_Europe_query = `SELECT name FROM country WHERE continent = "Europe"`;
const [query4] = await connection.query(select_Europe_query);
console.log('Countries in Europe:');
console.log(query4);

const select_areas_query = `SELECT name FROM country ORDER BY surfaceArea DESC`;
const [query5] = await connection.query(select_areas_query);
console.log('Countries ordered by surface area (descending):');
console.log(query5);

const select_NLD_query = `SELECT name FROM city WHERE countryCode = "NLD"`;
const [query6] = await connection.query(select_NLD_query);
console.log('Cities in the Netherlands:');
console.log(query6);

const select_Rotterdam_query = `SELECT population FROM city WHERE name = "Rotterdam"`;
const [query7] = await connection.query(select_Rotterdam_query);
console.log('Population of Rotterdam:');
console.log(query7);

const select_LIMIT10_query = `SELECT name FROM country ORDER BY surfaceArea DESC LIMIT 10`;
const [query8] = await connection.query(select_LIMIT10_query);
console.log('Top 10 countries by surface area:');
console.log(query8);

const select_mostPopulation_query = `SELECT name FROM city ORDER BY population DESC LIMIT 10`;
const [query9] = await connection.query(select_mostPopulation_query);
console.log('Top 10 most populated cities:');
console.log(query9);

const select_sumPopulation_query = `SELECT SUM(population) AS world_population FROM country`;
const [query10] = await connection.query(select_sumPopulation_query);
console.log('World population:');
console.log(query10);

} catch (error) {
console.error('Error executing queries:', error.message);
} finally {
await connection.end();
}