Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Mysql Lab 2: Question Set 1

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

MySQL Lab 2 : Question Set 1

EMP TABLE:

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


7369 SAMIR CLERK 7902 17-Dec-80 9000 20
7499 ANKIT SALESMAN 7698 20-Feb-81 17000 400 30
7521 WASIM SALESMAN 7698 22-Feb-81 13500 600 30
7566 JONES MANAGER 7839 02-Apr-81 30750 20
7654 MOHIT SALESMAN 7698 28-Sep-81 13500 1500 30
7698 BARNALI MANAGER 7839 01-May-81 29500 30
7782 CHARLE MANAGER 7839 09-Jun-81 24500 10
7788 SONALI ANALYST 7566 09-Dec-82 31000 20
7839 KUSHAL PRESIDENT 17-Nov-81 52000 10
7844 TARUN SALESMAN 7698 08-Sep-81 16000 0 30
7876 ASHISH CLERK 7788 12-Jan-83 12000 20
7900 JAMES CLERK 7698 03-Dec-81 10500 30
7902 FALGUNI ANALYST 7566 03-Dec-81 32000 20
7934 MUKESH CLERK 7782 23-Jan-82 15000 10

DEPT TABLE:

DEPTNO DNAME LOC


10 ACCOUNTING DELHI
20 RESEARCH CHENNAI
30 SALES KOLKATA
40 OPERATIONS MUMBAI
Questions:
Q.1) List the employees who are either ‘SALESMAN’ or ‘CLERK’ in the Desc order.
Q.2) List the employees who joined in the month of which second character is ‘e’.
Q.3) List the total information of EMP table along with DNAME and Loc of all the employees Working
Under ‘SALES’ & ‘RESEARCH’ in the asc Deptno.
Q.4) How many employees in december month hire date.(use group by and having clause)
Q.5) Display 2nd highest salary employee details.
Q. 6) List out the employees who earn more than the lowest salary in department 10.
Q. 7)Display all employee in sales or operation department(use outer join).
Q.8)List out the common jobs in research and accounting departments in ascending order.(use set
operation)
Q.9)List out the distinct jobs in sales and accounting department.
Q.10) Display the Empno, Ename, job, Hiredate, department name and location,Experience of all
Managers.
Q. 11) No. of emps where at least two emps are clerks.
Q.12) List the emp whose sal<his manager but more than any other manager.
Q.13) List the employee name, job, sal, and dname except clerks and sort on the basis of highest sal.
Q.14) List the managers whose sal is more than his employees avg salary.
Set 1 Answer
Ans 1) select * from emp where job = ‘SALESMAN’ or job = ‘CLERK’ order by job desc;

Ans 2) select * from emp where to_char(hiredate,’mon’) like ‘_e_’; (OR)


select * from emp where to_char(hiredate,’mon’) like ‘_e%’;

Ans 3) select * from emp e ,dept d where (dname = ‘SALES’ or dname =’RESEARCH’ ) and e.deptno =
d.deptno order by e.deptno asc; (OR)
select * from emp e ,dept d where d.dname in (‘SALES’,’RESEARCH’) and e.deptno = d.deptno order by
e.deptno asc;

Ans 4) select to_char(hiredate,’mon’) month,count(*) from emp group by to_char(hiredate,’mon’)


having to_char(hiredate,’mon’) = dec;

Ans 5) select * from emp where sal=(select max(sal) from emp where sal<( select max(sal) from emp));

Ans 6)select * from emp where sal>any(select sal from emp where dept_no=10);

Ans 7) select Ename, d.dept_no,d.d_name from emp e,dept d where e.dept_no(+)=d.dept_no and
d.dept_no IN(select dept_no from dept where d_name IN(‘SALES’,’OPERATION’));

Ans 8)select job from emp where dept_no=(select dept_no from dept where d_name=’RESEARCH’)
intersect select job from emp where dept_no=(select dept_no from dept where
d_name=’ACCOUNTING’) order by job;

Ans 9) select job from emp where dept_no=(select dept_no from dept where d_name=’SALES’) union
select job from emp where dept_no=(select dept_no from dept where d_name=’ACCOUNTING’) ;

Ans 10) select e.ename,e.job, months_between(sysdate,hiredate) exp ,d.dname,d.loc from emp e ,dept
d where e.deptno = d.deptno and e.empno in (select mgr from emp ) ;

Ans 11) select d.dname,count(*) from emp e,dept d,where e.deptno = d.deptno and
e.job = 'CLERK' group by d.dname having count(*) >= 2;

Ans 12) select distinct W.empno,W.ename,W.sal from (select w.empno,w.ename,w.sal from emp
w,emp m where w.mgr = m.empno and w.sal<m.sal) W (select * from emp where empno in (select mgr
from emp)) where W.sal > A.sal; (OR)
select * from emp w,emp m where w.mgr = m.empno and w.sal < m.sal and w.sal > any (select sal from
emp where empno in (select mgr from emp));

Ans 13) select e.ename,e.job,e.sal,d.dname from emp e ,dept d where e.deptno = d.deptno and e.job
not in('CLERK') order by e.sal desc;

Ans 14) select * from emp m where m.empno in (select mgr from emp) and m.sal > (select avg(e.sal)
from emp e where e.mgr = m.empno ) ;
The subquery does the same as (select (avg(e.sal)),m.ename from emp e, emp m where
e.mgr=m.empno group by e.mgr,m.ename);

You might also like