0% found this document useful (0 votes)
14 views9 pages

Assignment 7

The document outlines an SQL assignment with multiple tasks related to various databases, including insurance, employee, salesman, and student databases. It includes instructions for creating tables, inserting records, and writing queries to retrieve and manipulate data. Specific tasks involve finding totals, averages, and updating records based on given conditions.

Uploaded by

arpanadk63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views9 pages

Assignment 7

The document outlines an SQL assignment with multiple tasks related to various databases, including insurance, employee, salesman, and student databases. It includes instructions for creating tables, inserting records, and writing queries to retrieve and manipulate data. Specific tasks involve finding totals, averages, and updating records based on given conditions.

Uploaded by

arpanadk63
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment 7(SQL)

1.

2. 2022 Fall

3. 2021 spring
4. 2021 fall

5. 2020 spring (Do only SQL)

6. 2020 fall
7. 2019 spring

8. 2019 fall
9. 2018 spring

10. 2018 fall


11. 2017 fall

12.

13. 2016 spring


14. 2016 fall

15. 2015 spring

16. Consider the insurance database of below, where the primary keys are underlined. Construct
the following SQL queries for this relational database.
person (driver-id, name, address)
car (license, model, year)
accident (report-number, date, location)
owns (driver-id, license)
participated (driver-id, car, report-number, damage-amount)

a. Find the total number of people who owned cars that were involved in accidents in 2015.
b. Find the number of accidents in which the cars belonging to “John Smith” were involved.
c. Delete the Range Rover belonging to “John Smith”.
d. Update the damage amount for the car with license number “AABB2000” in the accident with
report number “AR2197” to $3000.
17.

Write SQL for the following


Employee (Eid, Ename, Eaddress, Egender)
Works (Bid, Eid)
Branch (Bid, Bname, Salary, Baddress)
a) Create all tables and insert 5 different records (use constraints as well).
b) Display the information of an employee who works at the same address as
their branch lies.
c) Find the 2nd highest salary of an employee.
d) Find the top 3 employee who earns the highest salary.
e) Sort all the information of an employee and branch by Ename.
f) Find the employee’s name and address who works in the ‘ABC’ branch
g) Find the total no of branches.
h) Find the avg salary of an employee whose name starts and ended with ‘s’.
i) Find the information about a female employee who works in ‘ABC’ branch
and earns a salary more than the avg salary of an employee.
j) Find the name of the department in which no employee works.
k) What is the highest salary among males?
l) What is the number of an employee who works in ‘ABC’ branch?
m) What is the highest salary in each department?
n) What is the total salary distributed in the ‘ABC’ branch?
o) Display information of an employee who works in either address
(Ktm,Cht,Pkr) and id < 4.
p) Increase the salary of an employee by 20% whose id is between 4-5
18.
Write SQL for following
Salesman (Sid,name,Scity,commission,Gender)
Orders(Ono,Purchase_amount,Order_date,Cid,Sid)
Customer(Cid,Name,CCity,grade,Gender)
a) Create all tables and insert 5 different records (use constraints as well).
b) Find that salesman with all information whose name containing the 1 st
character is ‘S’ and the 4th character is ‘A’ and the rest may be any character.
c) Find the highest purchase amount on date 2023-07-22 for each salesman
with their ID.
d) Count the customers with grades above Kathmandu’s average.
e) Display the information of the salesman with the highest commission and
from Chitwan.
f) Find the 2nd highest purchase amount.
g) Find the top 3 students who earn the highest commission.
h) Sort all the information of the salesman and order by commission.
i) Find the salesman’s name and commission who belongs to same city as the
customers.
j) Find the total no order order_date wise.
k) Find the avg purchase_amount of order.
l) Find the information about a female customer who is from ktm and purchase
orders more than the avg purchase_amount.
m) Find the name of a salesman who sale to customers with the same gender of
themself.
n) What is the highest commission among males?
o) What is the number of customers with ‘5’ grades?
p) What is the total commission of salesman whose name starts with p?
19.
Write SQL for following
Student (Sid, Sname,Sgender, Saddress)
Result(Gid,Sid)
Grade(Gid,Marks,Grade,stream)
a. Create all tables and insert 5 different records (use constraints as well).
b. Display the information of an student who score highest marks and from
chitwan.
c. Find the 2nd highest marks of an student.
d. Find the top 3 students who earns the highest marks.
e. Sort all the information of an student and grade by Sname.
f. Find the employee’s name and address who score ‘A’ grade.
g. Find the total no student gender wise.
h. Find the avg marks of student whose name starts and ended with ‘s’.
i. Find the information about a female student who is from KTM and scores a
marks more than the average marks of the student.
j. Find the name of the student to whom no grade is assigned.
k. What is the highest marks among males?
l. What is the number of students who score ‘B’ grades?
m. What is the highest marks in each stream?
n. What is the total marks scored in each stream of science and management?
o. Display information of students who is from either Ktm, Cht, pkr and
id < 4.
p. Increase the marks of students by 20% whose age is 20 male and marks in
between 20-30.
20. Explain stored procedure and view in SQL with an example.

You might also like