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
94 changes: 94 additions & 0 deletions Week1/Hadidreem17/setup_meetup_db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const { Client } = require("pg");

async function main() {
const client = new Client({
user: "hyfuser",
host: "localhost",
database: "postgres",
password: "hyfpassword",
port: 5432,
});

await client.connect();

console.log("Dropping database if exists...");
await client.query("DROP DATABASE IF EXISTS meetup");

console.log("Creating database meetup...");
await client.query("CREATE DATABASE meetup");

await client.end();


const meetupClient = new Client({
user: "hyfuser",
host: "localhost",
database: "meetup",
password: "hyfpassword",
port: 5432,
});

await meetupClient.connect();

console.log("Creating tables...");

await meetupClient.query(`
CREATE TABLE Invitee (
invitee_no SERIAL PRIMARY KEY,
invitee_name VARCHAR(100),
invited_by VARCHAR(100)
);
`);

await meetupClient.query(`
CREATE TABLE Room (
room_no SERIAL PRIMARY KEY,
room_name VARCHAR(100),
floor_number INT
);
`);

await meetupClient.query(`
CREATE TABLE Meeting (
meeting_no SERIAL PRIMARY KEY,
meeting_title VARCHAR(200),
starting_time TIMESTAMP,
ending_time TIMESTAMP,
room_no INT REFERENCES Room(room_no)
);
`);

console.log("Inserting sample data...");

await meetupClient.query(`
INSERT INTO Invitee (invitee_name, invited_by) VALUES
('Sara', 'Ali'),
('John', 'Lina'),
('Maya', 'Omar'),
('Noor', 'Samir'),
('Adam', 'Lara');ssss
`);

await meetupClient.query(`
INSERT INTO Room (room_name, floor_number) VALUES
('Blue Room', 1),
('Red Room', 2),
('Green Room', 1),
('Orange Room', 3),
('VIP Room', 5);
`);

await meetupClient.query(`
INSERT INTO Meeting (meeting_title, starting_time, ending_time, room_no) VALUES
('Tech Meetup', NOW(), NOW() + INTERVAL '2 hours', 1),
('Startup Pitch', NOW(), NOW() + INTERVAL '1 hour', 2),
('Workshop JS', NOW(), NOW() + INTERVAL '3 hours', 3),
('Design Basics', NOW(), NOW() + INTERVAL '4 hours', 4),
('AI Conference', NOW(), NOW() + INTERVAL '5 hours', 5);
`);

console.log("All done");
await meetupClient.end();
}

main();
83 changes: 83 additions & 0 deletions Week1/Hadidreem17/world_queries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
const { Client } = require("pg");

async function main() {
const client = new Client({
user: "hyfuser",
host: "localhost",
database: "world",
password: "hyfpassword",
port: 5432,
});

try {
await client.connect();

console.log("\n1. Countries with population > 8 million:");
let result = await client.query(`
SELECT name FROM country WHERE population > 8000000;
`);
console.log(result.rows);

console.log("\n2. Countries that contain 'land' in their names:");
result = await client.query(`
SELECT name FROM country WHERE name ILIKE '%land%';
`);
console.log(result.rows);

console.log("\n3. Cities with population between 500k and 1 million:");
result = await client.query(`
SELECT name FROM city
WHERE population BETWEEN 500000 AND 1000000;
`);
console.log(result.rows);

console.log("\n4. Countries in Europe:");
result = await client.query(`
SELECT name FROM country WHERE continent = 'Europe';
`);
console.log(result.rows);

console.log("\n5. Countries ordered by surface area DESC:");
result = await client.query(`
SELECT name, surfacearea FROM country ORDER BY surfacearea DESC;
`);
console.log(result.rows);

console.log("\n6. All cities in the Netherlands:");
result = await client.query(`
SELECT name FROM city WHERE countrycode = 'NLD';
`);
console.log(result.rows);

console.log("\n7. Population of Rotterdam:");
result = await client.query(`
SELECT population FROM city WHERE name = 'Rotterdam';
`);
console.log(result.rows);

console.log("\n8. Top 10 countries by surface area:");
result = await client.query(`
SELECT name, surfacearea FROM country ORDER BY surfacearea DESC LIMIT 10;
`);
console.log(result.rows);

console.log("\n9. Top 10 most populated cities:");
result = await client.query(`
SELECT name, population FROM city ORDER BY population DESC LIMIT 10;
`);
console.log(result.rows);

console.log("\n10. Total population of the world:");
result = await client.query(`
SELECT SUM(population) AS world_population FROM country;
`);
console.log(result.rows);

} catch (err) {
console.error("Error while running queries:", err);
} finally {
await client.end();
}
}

main();
15 changes: 15 additions & 0 deletions Week2/3_1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE authors (
author_id SERIAL PRIMARY KEY,
author_name VARCHAR(100),
university VARCHAR(100),
date_of_birth DATE,
h_index INT,
gender VARCHAR(20)
);

ALTER TABLE authors
ADD COLUMN mentor INT;

ALTER TABLE authors
ADD CONSTRAINT fk_mentor
FOREIGN KEY (mentor) REFERENCES authors(author_id);
106 changes: 106 additions & 0 deletions Week2/3_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
CREATE TABLE research_papers (
paper_id SERIAL PRIMARY KEY,
paper_title VARCHAR(200),
conference VARCHAR(200),
publish_date DATE,
field VARCHAR(100)
);

CREATE TABLE author_papers (
author_id INT,
paper_id INT,
author_order INT,
PRIMARY KEY (author_id, paper_id),
FOREIGN KEY (author_id) REFERENCES authors(author_id),
FOREIGN KEY (paper_id) REFERENCES research_papers(paper_id)
);

INSERT INTO authors (author_name, university, date_of_birth, h_index, gender, mentor) VALUES
('Alice Johnson', 'University of Amsterdam', '1980-04-12', 25, 'female', NULL),
('Bob Smith', 'Delft University of Technology','1975-09-03', 35, 'male', 1),
('Clara Nguyen', 'Erasmus University', '1985-01-22', 18, 'female', 1),
('David Lee', 'Utrecht University', '1990-07-15', 12, 'male', 2),
('Emma Rossi', 'Leiden University', '1982-11-05', 28, 'female', 2),
('Faisal Khan', 'TU Eindhoven', '1978-03-19', 40, 'male', NULL),
('Giulia Bianchi', 'University of Milan', '1988-09-30', 21, 'female', 6),
('Hassan Ali', 'Cairo University', '1983-02-10', 30, 'male', 6),
('Irene Müller', 'TU Berlin', '1986-06-25', 24, 'female', 1),
('Jamal Rahman', 'KU Leuven', '1991-12-01', 10, 'male', 8),
('Khadija Noor', 'Qatar University', '1989-04-09', 16, 'female', 6),
('Lars Jensen', 'Copenhagen University', '1977-08-14', 33, 'male', NULL),
('Maria Gonzalez', 'University of Barcelona', '1984-10-27', 27, 'female', 12),
('Nabil Hassan', 'American University of Beirut','1987-05-03', 19, 'male', 8),
('Olivia Brown', 'Oxford University', '1981-09-18', 38, 'female', 12);

INSERT INTO research_papers (paper_title, conference, publish_date, field) VALUES
('Efficient Database Indexing', 'ICDE', '2022-04-10', 'Databases'),
('Scalable Join Algorithms', 'VLDB', '2021-09-15', 'Databases'),
('Machine Learning for Query Optimization', 'NeurIPS', '2020-12-05', 'ML'),
('Graph Databases in Social Networks', 'SIGMOD', '2019-06-20', 'Databases'),
('Privacy in Distributed Systems', 'IEEE Security', '2018-03-11', 'Security'),
('Blockchain for Secure Storage', 'CryptoConf', '2022-07-02', 'Security'),
('Natural Language Interfaces to SQL', 'ACL', '2023-05-18', 'NLP'),
('Reinforcement Learning for Index Tuning', 'ICLR', '2021-04-27', 'ML'),
('Data Cleaning at Scale', 'KDD', '2019-08-22', 'Data Mining'),
('Approximate Query Processing', 'SIGMOD', '2020-06-17', 'Databases'),
('Time-Series Forecasting in Finance', 'ICDM', '2021-11-09', 'Data Mining'),
('Real-time Analytics on Streams', 'ICDE', '2023-04-03', 'Databases'),
('Energy-Efficient Data Centers', 'GreenIT', '2018-10-01', 'Systems'),
('Fault-Tolerant Replication', 'USENIX ATC', '2019-07-25', 'Systems'),
('Secure Multi-Party Computation', 'CryptoConf', '2020-09-30', 'Security'),
('Explainable AI for Healthcare', 'NeurIPS', '2022-12-10', 'ML'),
('Image Recognition with Deep CNNs', 'CVPR', '2019-06-15', 'CV'),
('Federated Learning on Edge Devices', 'MobiSys', '2021-06-08', 'ML'),
('Text Summarization with Transformers', 'ACL', '2020-07-06', 'NLP'),
('Question Answering over Knowledge Graphs', 'ISWC', '2022-10-19', 'NLP'),
('Anomaly Detection in Sensor Networks', 'ICDM', '2018-11-12', 'Data Mining'),
('Clustering High-Dimensional Data', 'KDD', '2017-08-18', 'Data Mining'),
('Optimization of Cloud Costs', 'SoCC', '2020-10-05', 'Cloud'),
('Container Orchestration at Scale', 'KubeCon', '2021-05-21', 'Systems'),
('Scheduling in Real-Time Systems', 'RTSS', '2019-12-03', 'Systems'),
('Knowledge Distillation Techniques', 'ICLR', '2022-04-15', 'ML'),
('Domain Modeling for Enterprise Apps', 'DDDConf', '2018-09-07', 'Software Eng'),
('Testing Microservices Architectures', 'ICSE', '2020-05-02', 'Software Eng'),
('CI/CD Pipelines in Large Organizations', 'DevOpsDays', '2021-03-29', 'DevOps'),
('Monitoring and Observability Best Practices','SREConf', '2023-01-13', 'DevOps');

INSERT INTO author_papers (author_id, paper_id, author_order) VALUES
(1, 1, 1),
(1, 2, 1),
(2, 2, 2),
(2, 5, 1),
(3, 7, 1),
(3, 19, 1),
(4, 8, 1),
(4, 10, 2),
(5, 4, 1),
(5, 10, 1),
(5, 12, 2),
(6, 5, 2),
(6, 6, 1),
(6, 15, 1),
(7, 9, 1),
(7, 21, 1),
(8, 11, 1),
(8, 20, 2),
(9, 3, 2),
(9, 12, 1),
(9, 16, 2),
(10, 13, 1),
(10, 14, 2),
(11, 16, 1),
(11, 18, 1),
(12, 17, 1),
(12, 24, 2),
(13, 22, 1),
(13, 27, 1),
(14, 18, 2),
(14, 23, 1),
(14, 25, 2),
(15, 26, 1),
(15, 28, 1),
(15, 29, 1),
(1, 30, 2),
(2, 30, 1),
(3, 11, 2),
(4, 1, 2);
16 changes: 16 additions & 0 deletions Week2/3_3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SELECT
a.author_name AS author,
m.author_name AS mentor
FROM authors a
LEFT JOIN authors m
ON a.mentor = m.author_id;

SELECT
a.*,
rp.paper_title
FROM authors a
LEFT JOIN author_papers ap
ON a.author_id = ap.author_id
LEFT JOIN research_papers rp
ON ap.paper_id = rp.paper_id;

37 changes: 37 additions & 0 deletions Week2/3_4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SELECT
rp.paper_id,
rp.paper_title,
COUNT(ap.author_id) AS number_of_authors
FROM research_papers rp
LEFT JOIN author_papers ap
ON rp.paper_id = ap.paper_id
GROUP BY rp.paper_id, rp.paper_title
ORDER BY rp.paper_id;

SELECT
COUNT(DISTINCT ap.paper_id) AS total_papers_by_female_authors
FROM authors a
JOIN author_papers ap
ON a.author_id = ap.author_id
WHERE a.gender = 'female';

SELECT
university,
AVG(h_index) AS avg_h_index
FROM authors
GROUP BY university;

SELECT
a.university,
COUNT(DISTINCT ap.paper_id) AS total_papers
FROM authors a
LEFT JOIN author_papers ap
ON a.author_id = ap.author_id
GROUP BY a.university;

SELECT
university,
MIN(h_index) AS min_h_index,
MAX(h_index) AS max_h_index
FROM authors
GROUP BY university;
Loading