Vous êtes sur la page 1sur 3

Perform the following queries: Table creation CREATE TABLE `employee` ( `empno` decimal(4,0) NOT NULL, `ename` char(10)

NOT NULL, `job` char(10) NOT NULL, `mgr` decimal(4,0) DEFAULT NULL, `hiredate` date NOT NULL, `sal` decimal(6,0) NOT NULL, `comm` decimal(4,0) DEFAULT NULL, `deptno` decimal(2,0) DEFAULT NULL, PRIMARY KEY (`empno`) ) example for insertion in table employee INSERT INTO `employee` (`empno`, `ename`, `job`, `mgr`, `hiredate`, `sal`, `comm`, `deptno`) VALUES ('7360', 'smith', 'clerk', '7902', '1980-12-17', '800',NULL, '20'); CREATE TABLE `dept` ( `deptno` decimal(2,0) NOT NULL, `dname` char(10) NOT NULL, `loc` char(10) NOT NULL, PRIMARY KEY (`deptno`) ) 1. List the names of analysts and salesman. select* ename from employee where job = 'analyst' or job = 'salesman'; 2 List details of employees who have joined before 30 Sep 1981. select * from employee where hiredate < '1981-09-30'; 3 List names of employees who are not managers. select * from employee where job <> 'manager'; 4 List names of employees whose employee numbers are 7369, 7521, 7839, 7934, 7788. select ename from employee where empno =7369 or empno = 7839 or empno = 7934 or empno = 7788; 7521 or empno =

5 List employees not belonging to department 30, 40 or 10. select * from employee where deptno <> 30 and deptno <> 40 and deptno <> 10; 6. List employee names for those who have joined between 30 June and 31 Dec. 81.

select * from employee '1981-12-31'

where hiredate > '1981-06-30'and hiredate <

7. List the different designations in the company. select DISTINCT job from employee; 8. List names of employees who are not eligible for commission. *select empno from employee where empno NOT IN(select empno from employee where comm>=0);* 9. List the name and designation of the employee who does not report to anybody. *select ename from employee where empno NOT IN(select empno from employee where mgr >0);* 10. List the employees not assigned to any department. *select empno from employee where empno NOT IN(select empno from employee where deptno>0);* 11. List names of employees who are eligible for commission. select* ename from employee where comm >=0;* 12. List names of employees whose names either start or end with S. select ename from employee where ename like '%s'or ename like 's%'; 13. List names of employees whose names have i as the second character. select* ename from employee where ename like '_i%'; . List the number of employees working with the company. select* count(empno) 'total' from employee; 14. List the number of designations available in the EMP table. select* count(DISTINCT job)'total' from employee; 15. List the total salaries paid to the employees. select sum(sal)'total' from employee; 17. List the maximum, minimum and average salary in the company. select* max(sal)'total' from employee; select* min(sal)'total' from employee; select* avg(sal)'total' from employee; 16. List the maximum salary paid to a salesman.

select max(sal)'total' from employee where job ='salesman';