SQL Queries Answers
March 18, 2017 | Author: Santosh Kumar Modekurty | Category: N/A
Short Description
Download SQL Queries Answers...
Description
SQL Queries:1. Display the details of those who do not have any person working under them? A: select e.ename from emp,emp e where emp.mgr=e.empno group by e.ename having count(*)=1; 2. Display the details of those employees who are in sales department and grade is 3? A: select * from emp where deptno = (select deptno from dept where dname='SALES') and sal between (select losal from salgrade where grade=3) and (select hisal from salgrade where grade=3); 3. Display those who are not managers and who are manager any one? A: 4. Display those employees whose name contains not less than 4 characters? A: select ename from emp where length(ename)>4; 5. Display those department whose name starts with “S” while the location name ends with “O”? A: select dname, loc from dept where dname like ‘S%’ and loc like ‘%O’; 1row selectd; 6. Display those employees whose manager name is Steven? A: select first_name from employees where manager_id in ( select employee_id from employees where first_name=’Steven’); 14 rows selected. 7. Display those employees whose salary is more than 3000 after giving 20% increment? A: select first_name, last_name, salary old, (salary*0.2)+salary new_salary from employees where ((salary*0.2)+salary)>3000; 83 rows selected 8. Display all employees with their dept names? A: select e.first_name, e.last_name, e.department_id, d.department_name from employees e, departments d where e.department_id=d.department_id; 107 rows selected. 9. Display ename who are working in sales dept? A: select first_name, last_name from employees where department_id=( select department_id from departments where department_name=’Sales’); 34 rows selected. 10. Display employee name, dept name, salary and comm. For those sal in between 2000 to 5000 while location is Chicago? A: select ename,dname,sal,comm from emp,dept where sal between 2000 and 5000 and loc='CHICAGO' and emp.deptno=dept.deptno; 1 row selected 11. Display those employees whose salary is greater than his manager salary? A: select e.last_name from employees e, employees m where e.employee_id=m.manager_id and e.salary>m.salary; 12. Display those employees who are working in the same dept where his manager is working? A: select m.ename from emp e, emp m where e.empno=m.mgr and m.deptno=e.deptno; 11 rows selected. 13. Display those employees who are not working under any manager? A: select ename from emp where mgr=null; no rows selected. 14. Display grade and employees name for the dept no 10 or 30 but grade is not 4 while joined the company before 31-dec-82?
A: select grade,ename from salgrade,emp where sal between losal and hisal and deptno in (10,30) and grade4 and hiredate= any (select sal from emp); 13 rows selected. 30. Display those employees whose salary is less than his manager but more than salary of any other managers? Only half 31. Display all the employees names with total sal of company with each employee name? 32. Find out the last 5(least) earners of the company? 33. Find out the number of employees whose salary is greater than their manager salary? A: select e.ename from emp m, emp e where m.empno=e.mgr and m.sal=3; 42. Display those employees who joined in the company in the month of Dec? A: select ename from emp where to_char(hiredate,'MON')='DEC'; 43. Display those employees whose name contains “A”? A: select ename from emp where ename like('%A%'); 44. Display those employees whose deptno is available in salary? 45. Display those employees whose first 2 characters from hiredate = last 2 characters of salary? 46. Display those employees whose 10% of salary of equal to the year of joining. A: select ename from emp where to_char(hiredate,'YY')=sal*0.1; 47. Display those employee who are working in sales or research? A: select ename from emp where deptno in(select deptno from dept where dname in('SALES','RESEARCH')); 11rows selected. 48. Display the grade of Jones? A: select ename,grade from emp,salgrade where sal between losal and hisal and ename=’Jones’; 49. Display those employees who joined the company before 15th of the month? A: select ename from emp where to_char(hiredate,'DD')
View more...
Comments