SQL Exercise

March 18, 2018 | Author: Praveen Kumar Reddy Muchintala | Category: Information Retrieval, Salary, Database Index, Sql, Subroutine


Comments



Description

1.1.Data Retrieval Part I 1. Exercise See table structure of Designation_Master, Department_Master, Student_Master, Student_Marks, Staff_Master, Book_Master and Book_Transaction table. Query Student_Code, Student_Name and Department_Code of every Student. Retrieve detail of every Student and Staff. Display Student_Code, Subjects and Total_Marks for every student. Total_Marks will calculate as Subject1 + Subject2 + Subject3 from Student_Marks. . Display Student_Code, Student_Year, Subjects and Percentage of all student and heading for the columns would be Student#, Join_Year, Subject1, Subject2, Subject3, Total, and Percentage from Student_Marks. Create a query to display unique Department_Code from Student_Master table. . Create a query which will display all students’ data those who are passing (getting pass Subject1 + Subject2 + Subject3 > 180. And save the query . Create a query which displays Student_Code, Join_Year and Subject 1 of all students who scored more than 75 in Subject1. And save the query Modify the query to display student detail of those who getting marks in Subject1 between 50 and 75. And save the query . Write a query which will display Student_Name, Departmnet_Code and DOB of all students who born between January 1, 1981 and March 31, 1983. Order the query in ascending order of DOB. 2. 3. 4. 5. 6. 7. 8. 9. 10. . Write a query which will display Student_Name, Department_Code of all students’ studies in departments 10 and 30, in alphabetical order by name. 11. Select Student_Name and Department_Code of all students those who have born in 1982. 12. . Display Book_Details for all books which have not being returned. 13. . Display Book_Details for all books which have not being returned and expected returned was last Monday. 14. . Select all students who have completed 25 years of age and their name starts with ‘S’; 15. . Display Student_Code & Year, of all students who is getting more than 60 in each subject and aggregate of marks is greater then 190 for year 2006 or 2007. KING FORD 12000 10000 XXXXXXXXXX XXXXXXXXXXXX 24. Write a query that produces the following for each staff : 28. . 25. Display Student_Name and Date of birth where DOB must be displayed in the format similar to “January. and Percentage as whole number for current year and percentage should be greater that 75. Total_Marks. 19. Label the column as ‘MONTHS WORKED’. Create a Query which display the Student_Name and Department_Code and Total_Marks and order it on Total_Marks descending and Student_Name ascending. 18. Display the Staff_Name. If student does not belong to any department. Hiredate and day of the week on which staff was hired. Salary of each staff. Order your result by number of months employed. . Display Student_Code. 30. Display each Staff_Name and number of months he worked for the organization. Display the Staff_Name Staff_Salary and the Salary in X. List the Book details issued to Students for current month and last month. . Display Staff_Name. 31. Sample Output. 17.999. Review date is first Monday after six months of Service. Format the salary to be 15 character long and left padded with ‘$’. . 22. Create a Query which displays the Student_Name and Department_Code. Hiredate and review date of all staff.00. Subject3. 23. 27. Label the column as DREAM SALARY. put “No Department”. . Write a query that displays Staff_Name. and Grade of all staff. <Staff_Name> earns <Salary> monthly but wants <2 times salary. Modify the query to add a column that will find the difference between Total_Marks and Maximum_Marks. Student_Name first letter capitalized and all other letters lower case and length of the Student_Name for all students whose name starts with ‘S’ or ‘J’. 12 1981” for those who born on Saturday or Sunday. 99. Label the Column REVIEW 26. Subject1. Write a query which displays Student_Name in upper case. Format the dream salary as Rs. Round the number of months to closest whole number. List all Table Name contains ‘MASTER’ in their names. Subject2. 29. Label the column as DAY. Grade depends on the following table. Label the column as “Department”. 21. . 20. Create a query which will display Staff_Name. Each X represents a 1000 in Salary. Label the column as “Diff_Marks”.16. Salary Salary >=50000 Grade A . Salary. Order the result by the day of the week staring with Monday. Total & Average salary of all staff. Label the heading as PAY DATE. Display the date in the format “Twenty Eighth of January. Staff_Name Department_Name. 39. Staff_Name. Manager. Department_Name. Subject2. Sudent_Name. 34. 35. 41. Round the result to nearest whole number. Staff Hiredate. Department_Name and Department_Code Salary for all staff who earns more than 20000. Manager_Name and salary of lowest paid staff in that manager’s team. Write a query which displays Staff_Name. Create a query that will display Student_Code. Department_Name. Pay date is the last Friday of the month. and Department_Name for all staff who do not works in Department code 10 and have ‘A’ in their name. Label the columns Staff#. Staff_Name. Salary. Edit the above query and display the same for each Department Name. 36. Determine the number of managers without listing them. Write a query to display number of people in each Department. Mgr#. Display the Manager_Name and the total strength of his/her team. . Department_Code. Dept_Code 10 20 30 1980 1 1981 2 2 6 1982 1 1 1983 1 Total 3 5 6 Part II 40. 37. Create a query which will give the following output ignore the lines. 2002”. Order you result on descending order of salary. Subjec1. 43. Write a query to display Staff_Name. and his manager’s number and name. 38. Display Staff_Code. Write a query to find the pay date for the month. Output should display Department_Code. 42. Save the query as E2Q20. Label the column as ‘Total Number of Managers’. and Subject3 for all students who are getting more than 60 in each subject from department 10 and 20. 44. 33. Exclude any group where minimum salary is less than 10000. Lowest. Display Manager_Code. Display the Highest.Salary >= 25000 < 50000 Salary>=10000 < 25000 OTHERS B C D 32. Minimum. Manager Hiredate of all staff hired before their manager. Label the columns Maximum. Create a query which will display Manager_Name. and Number of People. Total and Average respectively. Book_Name for those authors who wrote more than one book. Staff Code Staff Name Designation Department Name Department Head For all staff excluding HOD (List should not contain the details of Department head). Staff_Name who are not Manager. Create a query that will display Student_Code. Department_Name. 50. 47. 57. and Salary for those who are getting less than the average salary of organization. Fine will be calculated as Rs. 55. Department Name for those who have taken more than one book. Display Staff_Code. 52. Book Code. Create a query that will display the Staff_Name. Book_Code. List the Student_Code. Student_Name for that student who got highest marks in all three subjects in Computer Science department for current year. 51. List Staff_Code. Designation.45. Student_Name. Display Author_Name. 59. Staff_Name. Total. Sudent_Name. Issue_Date. Student_Name. Book_Code. Subject3. 60. Fine = 5 * (No. Staff Name. Book Name. Staff_Name. 53. List the Staff_Code. Book_Name. Generate a report which contains the following information Student Code Student Name Department Name Total Marks HOD Name Sort the output on Department Name and Total Marks. Generate a report which contains the following information. Create a query that will display Staff_Code. Department_Name. 49. 48. of Staff 10 20 30 Total 30 40 25 95 . List the total staff and the number of staff hired in each Department Department No No. Display Staff_Code. Department_Name. Fine For the staff who have not return the book. and Salary for those staff who are getting less then average salary in their own department 56. Department_Name. and Department_Name for that department in which there are maximum number of student are studying. 54. Department_Name. and Designation for those who have joined most recently. Designation. Subject1. Display top ten students for a specified department. Author. 58. 46. Display the Student_Code. Generate a report which contains the following information. Display the Staff_Name. Department_Name. For only those staff who have taken any book in last 30 days. Book_Name for all students whose expected book return date is today. Staff_Name. 5 per day. Department. Staff_Name. of days = Current Date – Expected return date). Details are: Student_Code. Staff Code. Subject2. and all the staff that work in the same department as a given staff. Give the column as appropriate label. Output should be in following format. . Accept a specific book code from user and find the details of the students/staff who have borrowed that book and has not returned the same. 72.61. Also display the department name where there is no staff. Salary (The highest and the lowest paid staff in his team). before expected date and after expected date. Output should be in following format. Book Code 100001 100002 100001 Total Book Name Author Status Java Complete Reference Schield Expected date C++ Complete Reference Schield Before date Oracle Complete Reference Scott After date Fine 0 0 15 15 64. List the department Name which has borrowed maximum number of time (Any book). Display the Manager_Name. Manager Name Staff_Name Allen Allen Ravi Raj Ajay Amit Raju Arvind 30000 Salary 10000 20000 15000 62. Send a report to every department in the following format: Dept Name. Staff_Name. Display Details for only (HOD/Professor/Reader/Lecturer). 71. Faculty Code Faculty Name Name Designation Department 66. List the books that are returned on expected date. Designation of all staff. For current year in which month maximum numbers of books are borrowed by which department? 69. and Department_Name. 67.Use Department Master & Designation Master. Write a query which will display Staff_Name. List the student detail. Generate the report that displays details for all books. who has borrowed maximum number of books. 5 per day. 63. Total No: of students yet to return the book 70. . Calculate the fine for books returned after due date as Rs. Accept the student code and display only faculty details of that department. The following details should be displayed Student/Staff Code Return Date Student/Staff Name Issue Date Expected 65. Display”NO STAFF” where there is no staff in the department.List the faculties of the department in which the student obtaining the maximum total marks for current year 68. List the details of the book which has not been borrowed so far. Generate a report which contains the following information.Book CodeBook Name Author Number of Times Issues 73. Book CodeBook Name Staff Code Name Number of Times Issued For current year only. Staff Name Designation Department . Staff_Name and Dept_Code. Display the structure of the view Staff_VU. OTHER OBJECTS Q1. Q2. Create an index on salary column of Staff_Master table.Primary key should generate numbers automatically Staff_Name – Should not be null Designation –Should always be one of them HOD / Reader/ Professor/ Lecturer. Q9. . Salary and Grade respectively. HireDate –Default should be current date Q9. Q8. Name: HARRIS. Q12. code. Dept_Code: 20. Sal: 25000. Department_Name. Do not allow a staff to be reassigned to another department through this view. Create a view Staff_VU from Staff_Master. Q3. Salary – Should be always >7000 Q8. Designation_Master & Dept_Master to make it possible to see where some one works. Create a view name DEPT20 that contains the staff code. Dept_Code – Should refer to the DEPT_Code in Dept_Master Q10. Create a table Dept_Master with the following columns DeptNo – Primary Key DeptName -. Delete all staff from department 20. staff name and department number for all staff in department 20. Q7. Create a table Staff_Master_Dup which contains the following columns: Staff_Code -. Salary and salary grade for all staff. Change the Miller’s department from 10 to 20. Mgr_Code: 7566. salaries and departments of all staff in department 10. Create a view consisting of names. Create a table called TEST with one column as Primary key. Q7.DML & DDL Statements Q1. Label the view column Staff_Code. Give all the staff in department 30 a salary hike of 10%. Select view name and text from USER_VIEWS. Display the contents of the STAFF_VU. Department. designation. Q6. Q2. Insert the values. Create a view FINANCE with data from the Staff_Master which gives their total salary and average salary. Q11. From the above view list the average annual salary for all the people in department 10 who makes less than 5000. Hiredate: 08-APR1985. What happened? Create a view called SALARY_VU based on the Staff_Name. Q10. Q13. Q3. Q4. Q5. Q5. Label the columns staff. Q14. Add a new staff with Staff_Code: 8888. Q4. Assign SMITH to department 30.It should not be null Q6. Confirm the same from data dictionary that the index is created. Display the structure of the DEPT20 view. Drop the table TEST and check that the corresponding index is also dropped. Write a procedure to find the manager of a staff. If the staff name is null raise a user defined exception. Q5. Handle exception if Staff_Code is not present or if it returns for more than one staff information. Create an index on Department_Code and Designation_Code of Staff_Master Q18.Q15.Write a sql script block to increase the salary by 30 % or 5000 whichever minimum for a given Department_Code. Write a function to compute the following. Confirm that an index is created implicitly. Bonus is twice of salary. < 1 Year Nil >=1 Year< 2 Year 10% of Salary . Dept_Code and Manager Name. Percent >= 80 then grade= A Percent >= 70 and < 80 then grade= B Percent >= 60 and < 70 then grade= C Else D Q1. For Grade: Student should pass in each subject individually (pass marks 60). Procedures . Display the error message if wrong department code has entered.Write a function to compute area of circle.Write a sql script to calculate bonus of staff for a given Staff_Code. Special Allowance will be decided based on the service in the company. Q16. Q4. Function. Q2. Function should take Staff_Code and return the cost to company. Write a function to compute age. HRA= 20% of Salary. Q4. DA = 15% Salary. triggers Q1. Staff_Name. Screen should display the following data – Staff_Code. TA= 8% of Salary. Display the error message if the wrong department code has entered. Q17. [Formula: PI * Radius**2]. (Note: The Department_Code will be accepted from user.) Q3. table. Write a sql script that generated the following report for a given Department code Subject1 Subject2 Subject3 Total Percentage Student_Code Sudent_Name Grade Note: Display suitable error massage if wrong department code has entered and if there is no student in the given department. The function should accept a date and return age in years.Write a sql script to retrieve all staff under specific department number and display the result. Q3. Write a procedure that accept staff code and update staff name to Upper case. Q2. Create an index on salary of Staff_Master table. Generate a report Using which displays the following information. Exp < 2 then no Update Exp > 2 and < 5 then 20% of salary Exp > 5 then 25% of salary Q8. Additional Allowance = Year of experience x 3000 Calculate the additional allowance and store Staff_Code.Status will be (Greater. Q7.5 year will be considered as 2 year). Write a procedure that displays the following information of all staff Staff_Name Department Name Designation Salary Note: . Lesser or Equal) respective to average salary of their own department. Write a procedure that accept Staff_Code and update the salary and store the old salary details in Staff_Master_Back (Staff_Master_Back has the same structure without any constraint) table.4 year will be considered as 1 year and 1. Procedure: Capture the value returned by the above function to calculate the additional allowance for the staff based on the experience. Create a procedure that accepts the book code as parameter from the user. Display an error message Staff_Master table is empty of if there is no matching record. Department Name: Computer Science Book Code Book Name Issue Date Student_Code Student Name 10001 C++ 11-Jan-07 10012 Raju 10005 Java 15-Jan-07 10011 Ravi . This function will take the hiredate of the staff as an input parameter. Issue Date 11-Jan-07 15-Jan-07 18-Jan-07 (Stu/Staff) 1001 10011 1005 Code (Stu/Staff) Allan Ravi Arvind Name HOD Student Book Code Book Name Designation 10001 C++ 10005 Java 10009 Oracle Lecturer Q12. and Experience in years and additional allowance in Staff_Allowance table. Date of Joining.>=2 Year< 4 Year >4 Year 20% of Salary 30% of Salary Status Q6. The following details should be displayed Student/Staff Code Ret_Date Student/Staff Name Issue Date Designation Expected Q9. Display the details of the students/staff that have borrowed that book and has not returned the same. Total Marks HOD Q11. Q10. The output will be rounded to the nearest year (1. Generate a report which displays the following information. Student Code Student Name Department Name Name For only top three students from each department and for current year.Write the following Function: This function will return years of experience for a staff. Generate a report which displays the following information. Department Name: Robotics Book Code Book Name Issue Date 10009 Oracle 18-Jan-07 Student_Code 10015 Student Name Arvind .
Copyright © 2022 DOKUMEN.SITE Inc.