Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
60 views

Index For SQL: Name: - Section: - Roll No.

The document contains instructions to create tables, insert data, and write SQL queries to retrieve data from the Employee and Department tables. The tables contain sample data about employees including name, salary, age, grade, department. The queries demonstrate using SELECT statements with WHERE, DISTINCT, logical operators, aggregation functions, ORDER BY, GROUP BY clauses and JOIN operations. The final questions are about altering tables, creating and dropping views, and dropping the tables.

Uploaded by

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

Index For SQL: Name: - Section: - Roll No.

The document contains instructions to create tables, insert data, and write SQL queries to retrieve data from the Employee and Department tables. The tables contain sample data about employees including name, salary, age, grade, department. The queries demonstrate using SELECT statements with WHERE, DISTINCT, logical operators, aggregation functions, ORDER BY, GROUP BY clauses and JOIN operations. The final questions are about altering tables, creating and dropping views, and dropping the tables.

Uploaded by

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

Index for SQL

Name: _____________________________ Section: ___ Roll No.: ____

Consider the tables given below and answer the questions that follow:

Table: Employee
No Name Salary Zone Age Grade Dept
1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
3 Naveen 32000 West 40 20
4 Uday 38000 North 38 C 30
5 Nupur 32000 East 26 20
6 Moksh 37000 South 28 B 10
7 Shelly 36000 North 26 A 30

Table: Department
Dept DName MinSal MaxSal HOD
10 Sales 25000 32000 1
20 Finance 30000 50000 5
30 Admin 25000 40000 7

Write SQL commands to:

Create Table / Insert Into


1. Create the above tables and insert tuples in them.
Simple Select
2. Display the details of all the employees.
3. Display the Salary, Zone, and Grade of all the employees.
4. Display the records of all the employees along with their annual salaries. The Salary column of the table
contains monthly salaries of the employees.
5. Display the records of all the employees along with their annual salaries. The Salary column of the table
contains monthly salaries of the employees. The new column should be given the name “Annual Salary”.
Conditional Select using Where Clause
6. Display the details of all the employees who are below 30 years of age.
7. Display the names of all the employees working in North zone.
8. Display the salaries of all the employees of department 10.
Using NULL
9. Display the details of all the employees whose Grade is NULL.
10. Display the details of all the employees whose Grade is not NULL.
Using DISTINCT Clause
11. Display the names of various zones from the table Employee. A zone name should appear only once.
12. Display the various department numbers from the table Employee. A department number should be displayed
only once.
Using Logical Operators (NOT, AND, OR)
13. Display the details of all the employees of department 10 who are above 30 years of age.
14. Display the details of all the employees who are getting a salary of more than 35000 in the department 30.
15. Display the names and salaries of all the employees who are working neither in West zone nor in Centre zone.
16. Display the names of all the employees who are working in department 20 or 30.
17. Display the details of all the employees whose salary is between 32000 and 38000.
18. Display the details of all the employees whose grade is between ‘A’ and ‘C’.
Using IN Operator
19. Display the names of all the employees who are working in department 20 or 30. (Using IN operator)
20. Display the names and salaries of all the employees who are working neither in West zone nor in Centre zone.
(Using IN operator)
Using BETWEEN Operator
21. Display the details of all the employees whose salary is between 32000 and 38000.
(Using BETWEEN operator)
22. Display the details of all the employees whose grade is between ‘A’ and ‘C’.
(Using BETWEEN operator)
Using LIKE Operator
23. Display the name, salary, and age of all the employees whose names start with ‘M’.
24. Display the name, salary, and age of all the employees whose names end with ‘a’.
25. Display the name, salary, and age of all the employees whose names contain ‘a’
26. Display the name, salary, and age of all the employees whose names do not contain ‘a’
27. Display the details of all the employees whose names contain ‘a’ as the second character.
Using Aggregate functions
28. Display the sum and average of the salaries of all the employees.
29. Display the highest and the lowest salaries being paid in department 10.
30. Display the number of employees working in department 10.
Using ORDER BY clause
31. Display the details of all the employees in the ascending order of their salaries.
32. Display the details of all the employees in the descending order of their names.
33. Display the details of all the employees in the ascending order of their grades and within grades in the
descending order of their salaries.
Using GROUP BY clause
34. Display the total number of employees in each department.
35. Display the highest salary, lowest salary, and average salary of each zone.
36. Display the average age of employees in each department only for those departments in which average age is
more than 30.
Using UPDATE, DELETE, ALTER TABLE
37. Put the grade B for all those whose grade is NULL.
38. Increase the salary of all the employees above 30 years of age by 10%.
39. Delete the records of all the employees whose grade is C and salary is below 30000.
40. Delete the records of all the employees of department 10 who are above 40 years of age.
41. Add another column HireDate of type Date in the Employee table.
Creating and Using VIEWs
42. Create a view West_Zone which displays the records of employees working in West zone only.
43. Create a view Above_30 which displays the records of only those employees who are above 30 years of age.
44. Display the data from the view West_Zone.
45. Display the records of the employees from the view Above_30 who work in the Sales department.
46. Using the view West_Zone increase the salary of all the employees by 12%.
JOIN of two tables
47. Display the details of all the employees who work in Sales department.
48. Display the Name and Department Name of all the employees.
DROP TABLE, DROP VIEW
49. Drop the views created above.
50. Drop the tables Employee and Department.

You might also like