Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

SQL Essential Training

User Assignment – 3

Problem Statement :

1. Find the number of employees in the customer table.

Ans: SELECT COUNT(*) FROM employee ;

2. Find the number of employees in the department 20.

Ans: SELECT department ,COUNT(*) FROM employee where


department=20;
3. Find all the employees whose name starts with ‘A’ and working in 10
department.

Ans: select * from employee where empName like 'a%' and department =
10;

4. Find all the distinct employees whose name starts with ‘R’.

Ans: select distinct empName from employee where empName like 'r%';

5. Find the sum of salaries of all employees in the customer table.


Ans: SELECT SUM(salary) FROM employee;

6. Find the sum of salaries of all employees working in 30 department.

Ans: SELECT SUM(salary) FROM employee where department=30;

7. Create a table called dept with columns department, location and


name.

Ans: create table dept(

deptno int,
dname varchar(14),

loc varchar(13),

);

8. Insert the following data to the dept table.

10,’finance’,’boston’

20,’marketing’,’vegas’

30,’IT’,’washington’

Ans: insert into dept values(10,'finance','boston');

insert into dept values(20,'marketing','vegas');

insert into dept values(30,'IT','washington');

9.Find all the employees who are working in finance department.

Ans: select * from employee where department = 'finance';


10.Find all the employees who are working in vegas.

Ans: select * from emp inner join dept on emp.deptno=dept.deptno where


loc='vegas';

11. Find all the employees who are working in IT and whose salary is
less than 25000

Ans: select * from employee where department ='IT' and salary <25000;
12. Find all the employees who are either working in finance
department or working in Washington.

Ans: select * from emp inner join dept on emp.deptno=dept.deptno

where loc like 'Washington' or dname like ‘finance’;

13. Find all the employees who are juniors to senior of the employee
working in the finance department.

Ans: select * from employee where department='finance' order by


datediff(sysdate(),date_of_joining) ;
14. Find the inner join of employee table on dept.

Ans: SELECT * FROM emp INNER JOIN dept ON emp.deptno =


dept.deptno;

15. Find the outer join of employee table on dept

Ans: SELECT * FROM emp left OUTER JOIN dept ON emp.deptno =


dept.deptno UNION

SELECT * FROM emp right OUTER JOIN dept ON emp.deptno =


dept.deptno

You might also like