Databases

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

BSc in Science in Computing & Multimedia

Stage 2, Semester 1
2022

Practical Laboratory Examination

Module Title Database Storage & Database Management


Module Code BSC20922
Weighting 15%
Maximal Possible Mark: 100 marks
Duration 2.5 hours

Instructions:

 Save your answer in a Microsoft Word document and submit the file through
Moodle.

Topic:
MySQL, Data definition language (DDL), Data Manipulation Language (DML)
24130 Joelma Rodrigues 24130@student.dorset-college.ie
You are given an eCommerce database as a MySQL SQL script. Please import the database
into the database through either MySQL Workbench or command line client. You then
need to answer the following questions regarding to this database.

The eCommerce database schema consists of the following tables:

 Customers: stores customer’s data.


 Products: stores a list of scale model cars.
 ProductLines: stores a list of product line categories.
 Orders: stores sales orders placed by customers.
 OrderDetails: stores sales order line items for each sales order.
 Payments: stores payments made by customers based on their accounts.
 Employees: stores all employee information as well as the organization structure
such as who reports to whom.
 Offices: stores sales office data.

Section 1: (2 x10 Marks = 20 Marks)

Using SQL command to find out the answers for the following question. You need to
provide both the SQL and the answer.

Q 1: Please list all the tables in this database.


[10 Marks]

show tables from ecommercecompany;

Q 2: What is the data type of the ‘creditLimit’ column of ‘Customers’ table.


[10 Marks]
describe customers; decimal(10,2)

Page 2 of 9
24130 Joelma Rodrigues 24130@student.dorset-college.ie

Section 2: (16x 5 marks = 80 Marks)

Provide the SQLs for the following questions.

Q 3. List all employee with their full name and job title.
[5 Marks]
select firstname, lastname, jobtitle from employees;

Q 4: How many employees are working as “Sales Rep” (job title).

[5 Marks]
select count(jobtitle) from employees
where jobtitle = 'Sales Rep';
Page 3 of 9
24130 Joelma Rodrigues 24130@student.dorset-college.ie

Q 5: List the customers whose credit limit is between 80 000.00 and 120 000.00.
[5 Marks]
select customerName, creditLimit from customers
where creditLimit between 80000 and 120000
order by creditLimit ASC;

Page 4 of 9
24130 Joelma Rodrigues 24130@student.dorset-college.ie
Q 6: List all customer who is from the city of NYC in country of USA, and their last names
begin with ‘L’ (tip: use contactLastName column).
[5 Marks]

SELECT * FROM customers


WHERE state = 'NY' and contactLastName like 'L%';

Q 7: From Costumers table, list countries and the number of customers from each country
by the order of the greatest number of customers to less number of customers.
[5 Marks]
SELECT country, count(country) FROM customers
group by country
order by count(country) desc;

Q 8: From Payments table, list all customer number, check number and payment amount
where the amount is less than 2000.00 [5 Marks]

select customernumber, checknumber, amount


from payments
where amount <2000;
Page 5 of 9
24130 Joelma Rodrigues 24130@student.dorset-college.ie

Q 9: From Payments table, calculate the total amount of all payments. [5 Marks]

select SUM(amount) as total_amount from payments;

Q 10: List the minimum, maximum and average payment amount in Payments table.
[5 Marks]
select MIN(amount) as min_amount, max(amount) as max_amount,
avg(amount) from payments;

Q 11: Find out how many payments have been made in November 2004 (paymentDate is
in November 2004). [5 Marks]

select count(paymentDate) as nov_2004_payment from payments


where paymentDate like '2004-11-%';

Page 6 of 9
24130 Joelma Rodrigues 24130@student.dorset-college.ie

Q 12: From Product table, list the distinct product lines and number of products within
each product where the number of products lines has quantity in store less than 50000.
[5 Marks]

Q 13: Display the details of the employees who are working in the offices located in
territory EMEA (hint: use subquery). [5 Marks]

select officeCode from offices


where territory = 'EMEA';

select * from employees


where officeCode = '4' or officeCode = '7';

Q 14: Display the number of products in each order and the average individual prices.
[5 Marks]
select productLine, count(productLine) from products
group by productLine;

Page 7 of 9
24130 Joelma Rodrigues 24130@student.dorset-college.ie
Q 16. Count how many employees working each office. [5 Marks]

select officeCode, count(officeCode) as employees_qt from employees


group by officeCode
order by employees_qt desc;

Q 15: For each office has more than 3 employees working in them, list office codes, cities,
and number of employees in each of those offices. [5 Marks]

select * from offices;


select postalCode, city from offices
where officeCode = 1 or 4 or 6;

Q 17. List all employees who works in Boston and NYC. (Hint: use subquery) [5 Marks]

select officeCode, city from offices


where city = 'Boston' or city = 'NYC';

select officeCode, firstname, lastname from employees


where officecode = 2 or officeCode = 3;

Page 8 of 9
24130 Joelma Rodrigues 24130@student.dorset-college.ie

Q 18. List all the products that their MSRP (manufacturer’s suggested retail price) is
greater than the average MSRP of all products, and display by how much is the difference.
[5 Marks]

Page 9 of 9

You might also like