DBMS File Section B
DBMS File Section B
FILE
DATABASE MANAGEMENT SYSTEM LAB CODE :LC-CSE-209G
Course : B. Tech
INDEX
S no. Assignment Date sign
4 View 31 oct
5 Queries 7 nov,14 Nov
1. Bank sql
➢ Salesman table
➢ Customer table
➢ Orders table
2. Queries
1. Display name and commission of all the salesman. ANS: select
3. Display names and city of salesman who belong to the city of Paris.
4. Display all the information for those customers with a grade of 200.
5. Display the order number,order date and the purchase amount for
order(s) which will be delivered by the salesman with ID 5001.
7. Find those salesman with all information who gets the commission
within the range of 0.12 and 0.14.
8. Find all those customers with all information whose names are ending
with the letter ‘n’.
9. Find those salesman with all the information whose name containing
the
1st character is ’N’ and the 4th character is ‘l’ abd rests may be any
character.
11. Fing the total purchase amount of all orders. ANS: select
12. Find the numbers of salesman currently listing for all their customers.
13. Find the highest grade for each of all the cities of all the customers.
14. Find the highest purchase amount of ordered by the each customer
with their ID and highest purchase amount.
16. Find the highest purchase amount on a date ‘2016-08-17’ for each
salesman with their ID.
17. Find the highest purchase amount of with their customer ID and order
date, for those customers who have the highest purchase amount in a
day is more than 2000.
18. Write a SQL statement that counts all orders for a date August 17th
2016.
ANS: select count(*) from orders where order_date=’2016-08-17’;
19. Find the name and city of those customers and salesman who lives in
the same city.
20. Find the name of all the customers along with the salesman who works
for them.
21. Display all those orders by the customers not located in the same cities
where their salesmen live.
22. Display all the orders issued by the salesman ‘Paul Adams’ from the
orders table.
ANS: select * from orders where salesman_id=(select salesaman_id from
salesman where name=’Paul Adams’);
23. Display all the orders which values are greater than the average order
value for the 10th October 2016.
25. Extract the data from the orders tables for the salesman who earned
the maximum commission.
26. Find the name and IDs of all salesman who had more than one
customer.
ANS: select salesman_id,name from salesman as a where 1<(select
count(*) from customer as c where c.salesman_id=a.salesman_id);
27. Write a query to find all the salesman who worked for only one
customer.
28. Display all the orders that had amounts that were greater than at least
one of the orders from September 10th 2016.
29. Display only those customers whose grades are in fact, higher than
every customer in New York.
➢branch Table
➢client Table
➢privateowner Table
➢propertyforrent Table
➢registration table
➢staff table
➢viewing table
4. Queries
1. Produce a list of salaries for all staff, showing only the staff number,
the first and last names, and the salary details.
3. Write a SQL query to list the staff who work in London. Please show
their first name, last name and branchno.
4. Produce a list of monthly salaries for all staff, showing the staff
number, the first and last names, and the salary details.
6. Write a SQL query to list the unique position for female staff with salary
less than 10000.
ANS: SELECT distinct position FROM Staff WHERE sex='F' and salary <
10000;
11. Find all owners with the string ‘Glasgow’ in their address.
12. List the details of all viewings on property PG4 where a comment has
not been supplied.
13. Produce a list of salaries for all staff, arranged in descending order of
salary.
15.. Write a SQL query to display the total salary of all staff.
16. Write a SQL query to list the unique branchno that branch has at least
two female staff.
17. Write the SQL query to show the branchno and the maximum salary for
each branch in the Staff table. The output should be sorted from high to
low based on the max salary of each branch;
ANS: NO, the statement invalid use of group function. Aggregation cannot
be in WHERE.
19. Write the SQL query to find how many properties cost more than $350
per month to rent?
21. Find the total number of Managers and the sum of their salaries.
24. For each branch office with more than one member of staff, find the
number of staff working in each branch and the sum of their salaries.
26. Write a SQL query to find the staff name (first name, last name) who
has salary higher than the average salary of branchno =’B003’;
ANS: Error, Subquery returns more than 1 row. Cannot use =, should use
IN
28. Write a SQL query to display the staffno and working branch city for the
staff who has the lowest salary.
29. List the staff who work in the branch at ‘163 Main St’.
30. List all staff whose salary is greater than the average salary, and show
by how much their salary is greater than the average.
1. Create a view so that the manager at the branch B003 can see the
details only for staff who work in his or her office.
2. Create a view of the staff details at branch B003 that excludes salary
information, so that only manages can access the salary details for
staff who work at their branch.