DBMS ASSIGNMENT 1:
“SQL Queries”:
To Create a Schema, a Table, a View, an Index. Consequently run 10
Queries on it.
Name: Madhura Khalekar
Roll no: 25
TE AIDS
To create a table:
USE pollution_by_cities;
CREATE TABLE pollutionstats (
pollutionstats_id INT PRIMARY KEY,
city VARCHAR(100),
country VARCHAR(50),
AQI INT,
category VARCHAR(50)
);
To Insert Values:
INSERT INTO pollutionstats (pollutionstats_id,city,country,AQI,category)
VALUES
(1, 'Kinhasa', 'Democratic Republic of Congo' , 155, 'Unhealthy'),
(2, 'Manama', 'Bahrain' , 152, 'Unhealthy'),
(3, 'Jakarta', 'Indonesia' , 152, 'Unhealthy'),
(4, 'Dhaka', 'Bangladesh' , 117, 'Unhealthy for sensitive groups'),
(5, 'Dubai', 'United Arab Emirates' , 117, 'Unhealthy for sensitive groups'),
(6, 'Sao Paulo', 'Brazil' , 108, 'Unhealthy for sensitive groups'),
(7, 'Jerusalem', 'Israel' , 103, 'Unhealthy for sensitive groups'),
(8, 'Shanghai', 'China' , 99, 'Moderate'),
(9, 'Chengdu', 'China' , 98, 'Moderate'),
(10, 'Tel Aviv', 'Israel' , 86, 'Moderate');
To Create an Index:
CREATE INDEX idx_category ON pollutionstats(category);
To create a View:
CREATE VIEW most_polluted AS
SELECT city, AQI, category
FROM pollutionstats
WHERE AQI > 150;
Running 10 Queries as follows:
1) SELECT * FROM pollutionstats;
2) SELECT COUNT(*) FROM pollutionstats;
3) SELECT * FROM pollutionstats WHERE AQI < 100;
4) SELECT * FROM pollutionstats WHERE country = 'China';
5) SELECT * FROM pollutionstats WHERE pollutionstats_id <= 5;
6) SELECT * FROM pollutionstats WHERE category = 'Unhealthy for sensitive
groups';
7) SELECT COUNT(*) FROM pollutionstats WHERE AQI > 100;
8) SELECT AVG(AQI) AS avg_aqi FROM pollutionstats;
9) SELECT * FROM pollutionstats ORDER BY AQI DESC;
10) SELECT * FROM most_polluted;
List of all executed statements: