Cs SQL
Cs SQL
Page 2 of 64
Page 3 of 64
Page 4 of 64
Page 5 of 64
Page 6 of 64
Page 7 of 64
Page 8 of 64
Page 9 of 64
Page 10 of 64
Page 11 of 64
Page 12 of 64
Page 13 of 64
Page 14 of 64
Page 15 of 64
Page 16 of 64
Page 17 of 64
Page 18 of 64
Page 19 of 64
Page 20 of 64
Page 21 of 64
Page 22 of 64
Page 23 of 64
Page 24 of 64
Page 25 of 64
Page 26 of 64
Page 27 of 64
Page 28 of 64
Page 29 of 64
Page 30 of 64
Page 31 of 64
Page 32 of 64
Page 33 of 64
Page 34 of 64
Page 35 of 64
Page 36 of 64
Page 37 of 64
Page 38 of 64
Page 39 of 64
Page 40 of 64
Page 41 of 64
Page 42 of 64
Page 43 of 64
Page 44 of 64
Page 45 of 64
Page 46 of 64
Page 47 of 64
Page 48 of 64
Database Concepts/SQL
Consider the tables given below and answer the questions that follow:
Table: Employee
Table: Department
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.
Page 49 of 64
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”.
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 IN Operator
19. Display the names of all the employees who are working in department 20 or
30. (Using IN operator)
Page 50 of 64
20. Display the names and salaries of all the employees who are working
neither in West zone nor in Centre zone. (Using IN operator)
Page 51 of 64
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.
Page 52 of 64
Answers
Page 53 of 64
2. select * from employee;
Output :
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
Page 54 of 64
5. select name, 12*salary as Annual Salary, zone, grade from employee;
Output :
Name Annual Salary Zone Grade
Mukul 360000 West A
Kritika 420000 Centre A
Naveen 384000 West
Uday 456000 North C
Nupur 384000 East
Moksh 444000 South B
Shelly 432000 North A
Page 55 of 64
9. select * from employee where grade=' ';
Output :
No Name Salary Zone Age Grade Dept
3 Naveen 32000 West 40 20
5 Nupur 32000 East 26 20
Page 56 of 64
13. select * from employee where dept=10 and age<30;
Output : No rows selected
15. select name, salary from employee where not zone='West' and not zone='Centre';
Output :
Name Salary
Uday 38000
Nupur 32000
Moksh 37000
Shelly 36000
Page 57 of 64
18. select * from employee where grade>='A' and grade=<'C';
Output :
No Name Salary Zone Age Grade Dept
1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
4 Uday 38000 North 38 C 30
6 Moksh 37000 South 28 B 10
20. select name, salary from employee where zone not in('West','Centre');
Output :
Salar
Name y
Uday 38000
Nupur 32000
Moksh 37000
Shelly 36000
21. select * from employee where salary between 32000 and 38000;
Output :
No Name Salary Zone Age Grade Dept
2 Kritika 35000 Centre 30 A 10
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
Page 58 of 64
22. select * from employee where grade between 'A' and 'C';
Output :
No Name Salary Zone Age Grade Dept
1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
4 Uday 38000 North 38 C 30
6 Moksh 37000 South 28 B 10
7 Shelly 36000 North 26 A 30
23. select name, salary, age from employee where name like 'M%';
Output : 2 row(s) selected
Name Salary Age
Mukul 30000 28
Moksh 37000 28
24. select name, salary, age from employee where name like '%a';
Output : 1 row(s) selected
Name Salary Age
Kritika 35000 30
25. select name, salary, age from employee where name like '%a%';
Output : 3 row(s) selected
Name Salary Age
Kritika 35000 30
Naveen 32000 40
Uday 38000 38
26. select name, salary, age from employee where name not like '%a%';
Output : 4 row(s) selected
Name Salary Age
Mukul 30000 28
Nupur 32000 26
Moksh 37000 28
Shelly 36000 26
Page 59 of 64
27. select name, salary, age from employee where name like '_a%';
Output : 1 row(s) selected
Name Salary Age
Naveen 32000 40
Page 60 of 64
32. select * from employee order by salary desc;
Output : 7 row(s) selected
No Name Salary Zone Age Grade Dept
4 Uday 38000 North 38 C 30
6 Moksh 37000 South 28 B 10
7 Shelly 36000 North 26 A 30
2 Kritika 35000 Centre 30 A 10
3 Naveen 32000 West 40 20
5 Nupur 32000 East 26 20
1 Mukul 30000 West 28 A 10
Page 61 of 64
35. select min(salary),max(salary),avg(salary) from employee group by zone;
Output : min(salary) max(salary) avg(salary)
30000 35000 35000
32000 32000 32000
36000 38000 37000
37000 37000 37000
30000 32000 31000
42. create view west_zone as select * from employee where zone ='west';
Output : view created.
Page 62 of 64
43. create view above_30 as select * from employee where age>30;
Output : view created.
Page 63 of 64
49. drop view West_Zone;
Output : view dropped.
Page 64 of 64