0% found this document useful (0 votes)
2 views

Assignment 1

The document provides instructions for a final evaluation involving SQL queries and database operations. It includes multiple-choice questions (MCQs) related to SQL queries, tasks for data analysis using provided CSV files, and a section for identifying and rectifying errors in SQL queries. Students are required to execute SQL queries, document outputs, and submit their work in PDF format while avoiding plagiarism.

Uploaded by

ramukatoori236
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment 1

The document provides instructions for a final evaluation involving SQL queries and database operations. It includes multiple-choice questions (MCQs) related to SQL queries, tasks for data analysis using provided CSV files, and a section for identifying and rectifying errors in SQL queries. Students are required to execute SQL queries, document outputs, and submit their work in PDF format while avoiding plagiarism.

Uploaded by

ramukatoori236
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Unit-2 Final

Evaluation
Instructions:
1. Use any sql editor to attempt the below questions.
2. Write queries for each question wherever applicable.
3. Execute the queries in your console and get an output.
4. Copy the query from your console and take a screenshot of
output for each question, compile them for each question in a
word document.
5. Convert this word document into a PDF and submit it on the
Portal.
6. Strictly avoid plagiarism and or referring to the internet!
All the best !!!!
Section 1 - MCQs
Q1
You are given two tables, i.e., Employee personal details and Employee
Department details.

Table 1: emp_details Table 2: dept_details


EmpID EmpID
EmpName DeptID
Salary Dept Name
Write a query to find the 4th highest salary in each department.
A. select * from
(select a.emp_id,
a.emp_name,
a.salary,
b.dept_id,
b.dept_name,
ROW_NUMBER() over(partition by emp_id order by salary desc) as
rank_1
from emp_details a left join dept_details b
on a.emp_id = b.emp_id ) as c
where rank_1= 4

B. select * from
(select a.emp_id,
a.emp_name,
a.salary,
b.dept_id,
b.dept_name,
DENSE_RANK() over(partition by dept_id order by salary desc) as rank_1
from emp_details a , dept_details b
on a.emp_id = b.emp_id ) as c where rank_1= 4 ;
C. select * from
(select a.emp_id,
a.emp_name,
a.salary,
b.dept_id,
b.dept_name,
DENSE_RANK() over(partition by dept_id order by salary desc) as rank_1
from emp_details a inner join dept_details b
on a.emp_id = b.emp_id ) as c
where rank_1= 4
D. select * from
(select a.emp_id,
a.emp_name,
a.salary,
b.dept_id,
b.dept_name,
DENSE_RANK() over(partition by dept_id order by salary desc) as rank_1
from emp_details a left join dept_details b
on a.emp_name = b.emp_name ) as c
where rank_1= 4 ;
Q2
Given the tables below, write a SQL query that retrieves the personal data about alumni who
scored above 16 on their calculus class exam.

Table 1 : Alumni Table 2 : Evaluation Table 3: Curriculum


student_id student_id class_id
name class_id class_name
surname exam_date professor_id
birth_date Grade semester
faculty
A. select * from Alumni
where student_id in (select a.student_id
from Evaluation a , Curriculum b
on a.class_id = b.class_id
where class_name = 'Calculus' and a.Grade > 16 )

B. select * from Alumni


where student_id in (select *
from Evaluation a inner join Curriculum b
on a.class_id = b.class_id
where class_name = 'Calculus' and a.Grade > 16 )
C. select * from Alumni
where student_id in (select *
from Evaluation a , Curriculum b
where a.class_id = b.class_id
where class_name = 'Calculus' and a.Grade > 16 )
D. select * from Alumni
where student_id in (select a.student_id
from Evaluation a inner join Curriculum b
on a.class_id = b.class_id
where class_name = 'Calculus' and a.Grade > 16 )
Q3
From the following tables, write a SQL query to find the salesman id,names who had the order
values greater than the minimum order value of 10th October 2012

Sales_Team_Details:

salesman_id name city commission


5001 James New York 0.15
Hoog
5002 Nail Knite Paris 0.13
5005 Pit Alex London 0.11
5006 Mc Lyon Paris 0.14
5003 Lauson San Jose 0.12
Hen
5007 Paul Adam Rome 0.13
Order_id purchase_amou ord_date customer_id salesman_id
nt
70001 150.5 05-10-2012 3005 5002
70009 270.65 10-09-2012 3001 5005
Transaction_Details:
70002 65.26 05-10-2012 3002 5001
70004 110.5 17-08-2012 3009 5003
70007 948.5 10-09-2012 3005 5002
70005 2400.6 27-07-2012 3007 5001
70008 5760 10-09-2012 3002 5001
70010 1983.43 10-10-2012 3004 5006
70003 2480.4 10-10-2012 3009 5003
70012 250.45 27-06-2012 3008 5002
70011 75.29 17-08-2012 3003 5007
70013 3045.6 25-04-2012 3002 5001
A. select * from sales_team_details
where salesman_id in (
select a.salesman_id, ord_date, customer_id from sales_team_details a inner join
transaction_details b
on a.salesman_id = b.salesman_id
where purchase_amount > (select max(purchase_amount)
from transaction_details
group by (ord_date)
having ord_date = '2012-10-10'))
B. select * from sales_team_details
where salesman_id in ( select a.salesman_id from sales_team_details a inner join
transaction_details b
on a.salesman_id = b.salesman_id
where purchase_amount > (select max(purchase_amount)
from transaction_details
group by (ord_date)
having ord_date = '2012-10-10'))
C. select * from sales_team_details
where salesman_id in (
select a.salesman_id from sales_team_details a inner join
transaction_details b
on a.salesman_id = b.salesman_id
where purchase_amount > (select max(purchase_amount)
from transaction_details))

D. select * from sales_team_details


where salesman_id EXISTS (
select a.salesman_id from sales_team_details a inner join
transaction_details b
on a.salesman_id = b.salesman_id
where purchase_amount > (select max(purchase_amount)
from transaction_details
having ord_date = '2012-10-10'))
Q4
Write a query to find the first and last transaction date for each Customer

Table1 :
Customer_orders_table
Cust_ID
Order_ID
Order_date
Order_Qty
A. select customer_id, min(a.order_date) as first_transaction_date, max(b.order_date) as
last_transaction_date
from customer_orders_table a, customer_orders_table b;

B. select customer_id, a.order_date as first_transaction_date, b.order_date as


last_transaction_date
from customer_orders_table a, customer_orders_table b
where a.order_date = min(a.order_date) and b.order_date = max(b.order_date);
C. select customer_id, order_id, min(a.order_date) as first_transaction_date,
max(b.order_date) as last_transaction_date
from customer_orders_table as a inner join customer_orders_table as b
on a.customer_id = b.customer_id
group by customer_id;
D. select customer_id, min(order_date) as first_transaction_date, max(order_date) as
last_transaction_date
from customer_orders_table
group by customer_id;
Q5. What is a one-to-many relationship?

A. One table with unique values be related to a table that has multiple values for
each of the original values.
B. One table with not necessarily unique values be related to a table that has
multiple values for each of the original values.
C. One table with unique values be related to a table that has unique values same
as the original values.
D. None of the Above
Section 2
Data Files:
Owners.csv
Pets.csv
ProceduresDetails.csv
ProceduresHistory.csv
THE VET’S CLINIC
You are an Analyst working for a
Veterinarian Clinic. The Clinic’s owner wants
you to make some sense out of their data.

For the analysis, you have access to view


entire database which has tables, Pets.csv,
Owners.csv, ProceduresHistory.csv and
ProceduresDetails.csv. Upload these in your
SQL server console and do the below
analysis:
1. Identify the number of owner’s in each Zip Code
2. Extract the information about the owners who live either in “Grand
Rapids” or “Southfield”
3. Extract the information about the owners whose first name contains “n” and
Surname has at least 3 characters
4. Extract information for those pets whose owners live in either “Grand Rapids” or
“Southfield”.
5. Extract information about the pets along with a description of the procedure
performed on them
6. Same as 3 but only keep those pet ids which are present in pets.csv
7. Find the sum of the price incurred on each pet’s procedure but only consider those
pets whose name starts with ‘C’
8. Find the owner names who own more than 1 pet, if there are any
9. Find the count of procedures performed on each pet who are Dogs
10. Find the average price incurred by each owner for their pet’s procedure
11. Find the cumulative sum of total procedures performed for each pet at a
monthly level. (Use Self join and partition by both)
12. Extract information for those pets who have undergone procedure type
“Vaccinations” with subcode 3, 4 and 5 or undergone procedure type “General
Surgeries” with subcode 8,10,13,15,16. (Use both subquery and join)
13. Find the top 5 pets in terms of fees paid for all the procedures performed
14. Find 4 owners who paid the least fees for procedures performed on all their pets
15. Find first and last date of procedure performed on each of the pets. The output
should have columns (Pet Name, First Procedure Date, Last Procedure Date)
16. Find all the owners whose pet’s name does not begin from letters d to s.
17. Find 4 day rolling average price incurred by each pet Id
18. Create a Procedure to find pet ids whose services incurred fees greater than the input
price( which is passed as a parameter)
Section 3
Identify and rectify the errors in the below queries, if any:
1. DROP DB abc;
2. DELETE * FROM tablename where col1 > value;
3. SELECT * FROM tablename OVER (PARTITION BY col3) WHERE col1 =
‘value’;
4. SELECT col1, SUM(CAST(Col2 as VARCHAR(5)) FROM tbl

GROUP BY col1;

5. INSERT INTO DATABASE db_name FROM tbl;

You might also like