Cal List SQL
Cal List SQL
Cal List SQL
Semester: III
Subject: MCA 301(Advanced Database Management Systems)
Faculty Name: Patel Mehulkumar D.
Batch: 2009-2012
Create following tables and solve the given queries.
1. Salesman
SNUM SNAME CITY COMMISSION (%)
1001 PIYUSH LONDON 12
1002 NIRAJ SURAT 13
1003 MITI LONDON 11
1004 RAJESH BARODA 15
1005 ANAND NEW DELHI 10
1006 RAM AHMEDABAD 10
1007 LAXMAN BOMBAY 09
SNUM: A Unique number assign to each salesman.SNAME: The name of salesman.
CITY: The location of salesman.
COMMISSION: The salesman commission on order.
2. Customer
CNUM CNAME CITY RATING SNUM
2001 HARDIK LONDON 100 1001
2002 GITA ROME 200 1003
2003 LAXIT SURAT 200 1002
2004 GOVIND BOMBAY 300 1002
2005 CHANDU LONDON 100 1001
2006 CHAMPAK SURAT 300 1007
2007 PRATIK ROME 100 1004
4. List of snum of all salesmen with orders in order table without any duplicates.
6. List out names and cities of all salesmen in London with commission above 10%
7. List all customers excluding those with rating <= 100 or they are located in Rome.
8. List all order for more than Rs. 1000 except the orders of snum, 1003 of 10/04/99.
10. List all customers whose names begins with letter 'A' to 'G'
12. Find out the largest orders of salesman 1002 and 1007.
13. Calculate the total & average amount ordered.
15. Find the largest order taken by each salesman on each date with salesman
commission.
17. Count the no. of salesmen registering orders for each day.
18. Write a query on the order table that will produce the order number, salesman no and
amount of commission for that order.
21. Show the name of all customers with their salesman's name.
22. List all customers and salesmen who shared a same city.
23. List all orders by the customers not located in the same city as their salesman.
24. List all customers serviced by salesman with commission above 12%.
25. Calculate the amount of the salesman commission on each order by customer with
rating above 100.
26. Find all pairs of customers having the same rating with out duplication.
27. List all customers located in cities where salesman Niraj has customers.
28. Find all pairs of customers served by a single salesman with the salesman's name.
29. List all salesmen who are living in the same city without duplicate rows.
30. Produce the name and city of all the customers with the same rating as Hardik'.
33. List all orders that are greater than the average of April 10, 1999
36. Find all customers whose cnum is 1000 above than the snum of Niraj.
37. Count the no. of customers with the rating above than the average of 'Surat'.
38. Produce the name and rating of all customers who have above average orders.
39. Find all customers with orders on 3rd Oct. 1999 using correlate sub query.
40. Calculate the total amount ordered on each day eliminating the days where the
total amount as not at least Rs. 2000 above the maximum amount of that day.
41. Using correlated sub query find the name and number of all customers with rating
equal to maximum for their city.
42. Select the name and number of all salesmen who have customers their cities.
43. Find all salesmen who have customers with rating > 300
44. Find all salesmen for whom there are customers that follow them alphabetical order.
45. Find all customers having rating greater than any customer in 'Rome'.
46. List all order that has amount greater than at least one of the orders from 5th October
1999.
47. Find all orders with amounts smaller than any amount for a customer in 'Rome'.
48. Find all the customers who have greater rating than every customer in 'Rome'.
49. Select all customers whose rating doesn't match with any rating customer of 'Surat'.
50. List all customers whose ratings are equal to or greater than ANY 'Niraj'
51. Create a union of two queries that shows the names, cities and ratings of all
customers. Those with rating of >=200 should display 'HIGH RATING' and those
with < 200 should display 'LOW RATING'
52. Create another table Day totals with two-attribute date and total and insert rows into
this table from order table.
56. Salesman Miti has resigned. Reassign her number to a new salesman Gopal whose
city is Bombay and commission is 10%.
59. Suppose we have a table called sales Manager with the same definition as Salesmen
table. Company decides to promote salesmen having total order more than 5000 to
Sales Manager. Fill up the Sales Manager table.
60. Assume that we have a table called smcity. Store the information of all salesmen with
the customers in their home cities into smcity.
61. Create a table Bonus that contains date wise maximum amount of order for all
salesmen.
62. Create a table Multicust containing the salesmen with more than one customer.
63. New Delhi office has closed. Remove all customers assigned to salesmen in New
Delhi.
64. Delete all salesmen who have at least one customer with a rating of 100 from
salesmen table.
65. Find the smallest order for each day. Reduce the commission of all salesmen by 2%
who produce this order.
66. Write a command to create the salesmen table so that the default commission is 10%
with not NULL permitted, snum is the primary key and all names contain alphabets
only.
67. Create a view Rate count that gives the count of no. of customers at each rating.
68. Create a view that shows all the customers who have the highest ratings.
69. Create a view that shows all the number of salesman in each city.
70. Create a view to keep track of the total no of customers ordering, no of salesmen
taking orders, the no of orders, the average amount ordered, and the total amount
ordered for each day.
71. List all salesmen in London who had at least one customer located there as well.
72. List all salesmen in London who didn't have any customer there.
DEPT_MASTER
PK
DEPT_ID DEPT_NAME
DEPT_ID_1 HR
DEPT_ID_2 MARKETING
DEPT_ID_3 SALES
DEPT_ID_4 ACCOUNTS
DEPT_ID_5 FINANCE
DEPT_ID_6 PRODUCTION
DEPT_ID_7 MAINTANANCE
TRANS_MASTER
PK FK
TRANS_ID TRANS_DATE EMP_NO TRANS_TYPE TRANS_AMT
Do as directed.
1 Write a PL/SQL block to calculate department wise total salary and grand total of salary.
(Use simple cursor.)
OUTPUT
Total salary of HR department is 57000
Total salary of MARKETING department is 70000
Total salary of SALES department is 65000
Total salary of ACCOUNTS department is 70000
Total salary of FINANCE department is 80000
Total salary of PRODUCTION department is 95000
------------------------------------------------------------------
Grand total of the salary is =============== 587000
PL/SQL procedure successfully completed.
2 Accept employee number from user and calculate balance for that particular employee.
(Use parameterized cursor.)
OUTPUT1
Enter value for char_emp_no: 'EMP_NO_8'
Welcome HARESH.
Your Employee Number is EMP_NO_8.
Your Current Balance is 20000.
PL/SQL procedure successfully completed.
OUTPUT2
Enter value for char_emp_no: 'EMP_NO_89'
This employee does not exist. Please enter valid employee number.
PL/SQL procedure successfully completed.
3 Write a PL/SQL block that will display all the employees under their managers.
(Use nested cursors simple + parameterized.)
OUTPUT
EMP_NO_1 (RAJESH) is the manager of following employees.
EMP_NO_7 (DILIP)
====================================================================
EMP_NO_2 (MUKESH) is the manager of following employees.
EMP_NO_4 (SANKET)
====================================================================
EMP_NO_4 (SANKET) is the manager of following employees.
EMP_NO_3 (PRAGNESH)
EMP_NO_10 (RONAK)
====================================================================
EMP_NO_5 (DARSHAN) is the manager of following employees.
EMP_NO_9 (PRAMOD)
EMP_NO_2 (MUKESH)
====================================================================
EMP_NO_6 (BHARAT) is the manager of following employees.
EMP_NO_5 (DARSHAN)
====================================================================
EMP_NO_7 (DILIP) is the manager of following employees.
EMP_NO_8 (HARESH)
====================================================================
EMP_NO_8 (HARESH) is the manager of following employees.
EMP_NO_6 (BHARAT)
====================================================================
PL/SQL procedure successfully completed.
4 Accept department id from user and calculate balance of each employee of that particular department.
(Use nested cursors parameterized + parameterized)
OUTPUT1
Enter value for char_dept_id: 'DEPT_ID_1'
Welcome MUKESH.
Your Current Balance is 45000.
Welcome RONAK.
Your Current Balance is 25000.
You have entered invalid employee number. Please enter valid one.