Vous êtes sur la page 1sur 5

Assignment

Subject : Relational Database Systems

(1): Display all columns from dept table?


Ans: select * from department;

(2): Display deptno,loc from dept table?


Ans: select did,loc from department;

(3): Calculate the employee salary with increase of 300$ for all employee?
Ans: select Sal+300 AS 'Increased Salary' from emp;

(4): Display name,salary and annual compensation of employee?


Ans: select ename,Sal,Sal*12+100 AS 'Annual Compensation' from emp;

(5):Display annual salary of an employee whose name is 'King'?


Ans: select Sal*12 As 'Annual Salary' from emp where ename='King';

(6):Change the alias of ename column to 'Employee Name'?


Ans: select ename as 'Employee Name' from emp;
(7):Display Unique Designation from dept table?
Ans: select distinct dname from department;

(8):Display the list of employee who are in dept no 10?


Ans: select ename,job from emp where did=10;

(9):Display name and salary of employee who have salary between


10000to20000?
Ans: select ename,Sal from emp where Sal Between 10000 AND 20000;

(10):Display emp name,emp_no,dept_no of all employees whose names are


Sumair,umair etc?
Ans: select eid,ename,did from emp where ename IN ('Sumair','Umair');

(11):Display the name of employees whose name start from S?


Ans: select ename from emp where ename like 'S%';

(12):Display the name of employees whose name contains A_B ?


Ans: select ename from emp where ename like '%A_B%';

(13):Display the emp_no,emp_name,job,salary of employees who earn more


than 1100 and job is ''Clerks ?
Ans: select empno,ename,sal from emp where job='Clerk' and sal>1100;

(14):Display Hiring Date of employees in reverse order ?


Ans: select hiringdate from emp order by hiringdate desc;

(15):Display name,sal of employees who earn more then 1500 and not in dept
10,30 ?
Ans: select ename, Sal from employee where Sal>1500 and did Not In(10,30);
(16):Display the average, highest, lowest & sum of monthly salaries for all
employees?
Ans: select avg(Sal) as 'Average Monthly Salary', max(Sal) as 'Highest Monthly
Salary', min(Sal) as 'Lowest Monthly Salary', sum(Sal) as 'Sum Monthly Salary'
from emp Group by Ename, empno, sal;

(17):Display e_name that is first and empname that are last in alphabetized list
of all employees?
Ans: select ename from emp order by ename desc;

(18):Display employees information & no of employees who exists in dept 30?


Ans: select count(empno),ename,deptno from emp where depno=30;

(19):Display dept_id and average salaries of those dept that have an average
sallary greater than 2000$?
Ans: select did,avg(Sal) from department Group by did,ename,sal Having
avg(sal)>2000;

Join Queries

1)Display the employee name and department number for all employees?
Ans: SELECT employee.e_name, employee.did, department.d_name FROM
employee,department WHERE employee.did = department.did;

2)Create a unique listing of all jobs that are in department 30, include the
location of department 30.
Ans: SELECT DISTINCT employee.job, department.loc FROM employee ,
department WHERE employee.did = department.did AND employee.did =
30;
3)Display ename,dname and loc of all employees who earns a commision.
Ans: SELECT employee.e_name, department.d_name, department.loc FROM
employee , department WHERE employee.did = department.did AND
employee.comm IS NOT NULL;

4)Display ename,dname of all employees who have 'A' in their names.


Ans: select employee.e_name,department.d_name from employee inner join
department on employee.did=department.did where employee.e_name
like '%A%';

5)Display the enames and empno along with their manager's names and
manager numbers.Label the colums Employee, E#, Manager and Mgr#.
Ans: select e.e_name as 'Employee',e.emp_id as 'E#',manager.mgr_id as
'Mgr#',manager.mgr_name as 'Manager' from employee e, employee
manager where e.mgr=manager.emp_id;

6)Display the ename and hiring date of any employee who are hired after
employee 'Blake'.
Ans: select e.e_name,e.hiring_date from employee, employee blake where
blake.ename ='Blake' and blake.hirng_date < employee.hirng_date;

SubQueries

1) Display ename and hiring date of all employees who are in the same
department as employee 'Blake'?
Ans: select e_name,hiring_date from employee where did IN (select did from
employee where e_name='Blake') and e_name!='Blake';
2) Display ename and empno of all employees who earns more than the
average salary. sort in descending order.
Ans: select emp_id,e_name from employee where Sal>(select avg(Sal) from
employee) order by Sal Desc;

3)Display ename and empno of all employees who works in a dept with any
employee whose name contains a 'T'?
Ans: select emp_id,e_name from employee where did in (select did from
employee where e_name like '%T%');

4)Write a query to display the name and deptno and salary of all employees
whose deptno and salary matches the deptno and salary of any employee who
earns a comm?
Ans: select e_name, did, Sal from employee where (did,Sal) in (select did,Sal
from employee where comm is not null);

5)Display ename and empno of all employees that earns a salary that is higher
than the salary of all of the clerks. Sort result on salary from highest to lowest.
Ans: select e_name,job,Sal from employee where Sal > All (select Sal from
employee where job='Clerk') order by Sal Desc;

Vous aimerez peut-être aussi