Lab Final Solution
Lab Final Solution
Fall 2017
Lab Final Paper
Registration No
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Overall
Total Marks 10 10 10 10 10 10 10 10 10 10 100
Ob. Marks
Instructions:
1) Understanding of question is part of paper. Therefore, no queries will be entertained during
examination.
2) abc_school.sql and northwind.sql files are uploaded on LMS. Use those files to attempt paper.
3) You can use any method or approach to solve a query unless you are explicitly instructed to use
specific approach.
4) Use proper indentation/formatting while writing queries.
5) You need to make a MS Word file of your solution + need to submit handwritten hardcopy too.
6) You need to write only queries on handwritten copy (not output table), but in MS Word file, you
need to write query (text form) + its output table (picture) if any.
7) Output table Column heading is given in paper, your output table column heading must match with it.
8) SOME ONE is always with You, so be Relaxed. SOME ONE is always watching You, so be Honest.
Keep Calm & stay Blessed.
abc_School Schema
Table Data
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Q 1: Mistakenly, Student_Contact Table is deleted, now write a query to re-create it. See Schema for
its Structure. Also Insert data in it. (5 + 5 Marks)
PhoneNumber varchar(25),
StudentID int,
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Q 2: Write a query that display total count of Male and Female Student. (2+ 8 MARKS)
Total Rows in Output: ___2______
from Student s
group by gender;
Q 3: Write a query that display all Students name, with their gender, Father Name and Mother Name
(USE JOINS). (2+ 8 MARKS)
from Guardian m
join
join
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Q 4: Write a query that display name of only those students whose name are unique in School. (No
other student has that same name). (2+ 8 MARKS)
from Student s
Group by s.Sname
having count(s.Sname)=1;
Q 5: Write a query that display Name of students with count of their real/step brother or Sister
enrolled in School. (2+ 8 MARKS)
Select s.StudentId as 'Student Id', S.Sname as 'Student Name', count(f.Sname) as 'Sibling Count'
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Q 6: Write a query that display all Father(Husband) Name in Alphabetical order from Guardian Table
with Total number of their Wives. (Use Nested Query to find Count of Wives). (2+ 8 MARKS)
from Guardian w
from Guardian h
order by h.GName;
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Northwind DB Queries
Q 7: Write a query that displays list of all different first name of employees from employees table in
ascending order. (2+ 8 MARKS)
FROM employees e
ORDER BY e.first_name
Q 8: Write a query that displays total count of those order which has no shipping fee. (2+ 8 MARKS)
Total Rows in Output: __1______
FROM orders o
WHERE o.shipping_fee = 0
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Q 9: Write a query that displays Name of that Products in ascending order which has not been
purchased by any supplier yet. (2+ 8 MARKS)
FROM products p
ORDER by p.product_name
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Q 10: Write a query that display Customers First Name and Last Name that has maximum numbers of
invoices. (Note: You will not Hardcode your query.) (2+ 8 MARKS)
FROM customers c
INNER join
orders o
INNER join
HAVING COUNT(i.id) = (
SELECT COUNT(i.id)
FROM customers c
INNER join
orders o
INNER join
limit 1
ORDER by c.first_name
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 1
Introduction to Database System
Fall 2017
Lab Final Paper (Version 2)
Registration No
Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 Overall
Total Marks 10 10 10 10 10 10 10 10 10 10 100
Ob. Marks
Instructions:
1) Understanding of question is part of paper. Therefore, no queries will be entertained during
examination.
2) birth_certificate.sql and northwind.sql files are uploaded on LMS. Use those files to attempt paper.
3) You can use any method or approach to solve a query unless you are explicitly instructed to use
specific approach.
4) Use proper indentation/formatting while writing queries.
5) You need to make a MS Word file of your solution + need to submit handwritten hardcopy too.
6) You need to write only queries on handwritten copy (not output table), but in MS Word file, you
need to write query (text form) + its output table (picture) if any.
7) Output table Column heading is given in paper, your output table column heading must match with it.
8) SOME ONE is always with You, so be Relaxed. SOME ONE is always watching You, so be Honest.
Keep Calm & stay Blessed.
Northwind DB Queries
Q 1: Write a query that list of all different category name from products table in ascending order. (2+ 8
MARKS)
FROM products
ORDER BY Category
Q 2: Write a query that displays Total customer count in each order_date. (2+ 8 MARKS)
Total Rows in Output: _28_____
group by (o.order_date)
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2
Q 3: Write a query that displays Name of that Products in ascending order which has not been ordered
by any customer yet. (2+ 8 MARKS)
FROM products p
ORDER by p.product_name
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2
Q 4: Write a query that display Customers First Name and Last Name that has maximum numbers of
invoices. (Note: You will not Hardcode your query.) (2+ 8 MARKS)
FROM customers c
INNER join
orders o
INNER join
HAVING COUNT(i.id) = (
SELECT COUNT(i.id)
FROM customers c
INNER join
orders o
INNER join
invoices i
limit 1
ORDER by c.first_name
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2
Birth_Certificate Schema
Table Data
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2
Q 5: Write a query that display all Father(Husband) Name in Alphabetical order from Parent Table with
Total number of their Wives. (Use Nested Query to find Count of Wives). (2+ 8 MARKS)
from Parent w
from Parent h
order by h.PName;
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2
Q 6: Write a query that display Name of children with count of their real/step brother or Sister. (2+ 8
MARKS)
Select c.ChildrenID as 'Children Id', c.Cname as 'Children Name', count(f.Cname) as 'Sibling Count'
Q 7: Write a query that display name of only those children whose name are unique. (No other child
has that same name). (2+ 8 MARKS)
from Children c
Group by c.Cname
having count(c.Cname)=1;
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2
Q 8: Write a query that display all Childrens name, with their gender, Father Name and Mother Name
(USE JOINS). (2+ 8 MARKS)
select c.Cname as 'Baby Name', c.Gender as 'Gender', f.PName as 'Father Name', m.Pname as 'Mother
Name'
from Parent m
join
join
Q 9: Write a query that display total count of Male and Female Children. (2+ 8 MARKS)
Total Rows in Output: __2____
from Children c
group by gender;
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2
Q 10: Mistakenly, Parent_Contact Table is deleted, now write a query to re-create it. See Schema for
its Structure. Also Insert data in it, present above in table. (5 + 5 Marks)
PhoneNumber varchar(25),
ParentID int,
The STRUGGLE youre in TODAY is developing the STRENGTH you need for TOMORROW
Version 2