SQL Submitted By: Lelia Winstead

SQL Submitted By: Lelia Winstead

<p> 1</p><p>SQL> -- Submitted by: Lelia Winstead SQL> SQL> set linesize 80 SQL> set pagesize 35 SQL> SQL> -- √ 1. Create a query to display the name and salary of employees SQL> -- earning a salary of more than $2850. Save your SQL statement SQL> -- to a file named p2q1.sql. Run your query. SQL> SQL> SELECT ename, sal 2 FROM EMP 3 WHERE sal > 2850;</p><p>ENAME SAL ------JONES 2975 SCOTT 3000 KING 5000 FORD 3000 </p><p>SQL> save p2q1.sql Created file p2q1.sql SQL> START p2q1.sql</p><p>ENAME SAL ------JONES 2975 SCOTT 3000 KING 5000 FORD 3000 </p><p>SQL> --√ 2. Create a query to display the employee name and department SQL> -- number for employee number 7566. SQL> SQL> SELECT ename,deptno 2 FROM EMP 3 WHERE empno = 7566;</p><p>ENAME DEPTNO ------JONES 20 </p><p>SQL> --√ 3. Modify p2q1.sql to display the name and salary for all SQL> -- employees whose salary is not in the range of $1500 and SQL> -- $2850. Resave your SQL statement to a file named p2q3.sql. SQL> -- Rerun your query. SQL> SQL> edit p2q1.sql</p><p>SQL> get p2q3.sql 1 SELECT ename, sal 2 FROM EMP 3* WHERE sal NOT BETWEEN 1500 AND 2850 SQL> / 2</p><p>ENAME SAL ------SMITH 800 WARD 1250 JONES 2975 MARTIN 1250 SCOTT 3000 KING 5000 ADAMS 1100 JAMES 950 FORD 3000 MILLER 1300 </p><p>10 rows selected.</p><p>SQL> -- √ 4. Display the employee name, job, and start date of employees SQL> -- hired between February 20, 1981, and May 1, 1981. Order the SQL> -- query in ascending order by start date. SQL> SQL> SELECT ename, job, hiredate 2 FROM EMP 3 WHERE hiredate BETWEEN '20-FEB-81' AND '01-MAY-81' 4 ORDER BY hiredate;</p><p>ENAME JOB HIREDATE ------ALLEN SALESMAN 20-FEB-81 WARD SALESMAN 22-FEB-81 JONES MANAGER 02-APR-81 BLAKE MANAGER 01-MAY-81 </p><p>SQL> -- √ 5. Display the employee name and department number of all SQL> -- employees in departments 10 and 30 in alphabetical order SQL> -- by name. SQL> SQL> SELECT ename, deptno 2 FROM EMP 3 WHERE deptno IN ('10', '30') 4 ORDER BY ename;</p><p>ENAME DEPTNO ------ALLEN 30 BLAKE 30 CLARK 10 JAMES 30 KING 10 MARTIN 30 MILLER 10 TURNER 30 WARD 30 </p><p>9 rows selected. 3</p><p>SQL> -- √ 6. Modify p2q3.sql to list the name and salary of employees who SQL> -- earn more than $1500 and are in department 10 or 30. Label the SQL> -- columns Employee and Monthly Salary, respectively. Resave your SQL> -- SQL statement to a file named p2q6.sql. Rerun your query. SQL> SQL> edit p2q3.sql</p><p>SQL> get p2q6.sql 1 SELECT ename AS "Employee", sal AS "Monthly Salary" 2 FROM EMP 3* WHERE sal > 1500 AND deptno IN ('10', '30') What happened to ORDER BY? SQL> /</p><p>Employee Monthly Salary ------ALLEN 1600 BLAKE 2850 CLARK 2450 KING 5000 </p><p>SQL> SQL> --√ 7. Display the name and hire date of every employee who was SQL> -- hired in 1982. SQL> SQL> SELECT ename, hiredate 2 FROM EMP 3* WHERE hiredate LIKE '%82';</p><p>ENAME HIREDATE ------MILLER 23-JAN-82 </p><p>SQL> SQL> --√ 8. Display the name and job title of employees who do not have SQL> -- a manager. SQL> SQL> SELECT ename, job 2 FROM EMP 3 WHERE mgr IS NULL;</p><p>ENAME JOB ------KING PRESIDENT </p><p>SQL> --√ 9. Display the name, salary, and commission for all employees SQL> -- who earn commissions. Sort the data in descending order SQL> -- of salary and commissions (commission within salary). SQL> SQL> SELECT ename, sal, comm 2 FROM EMP 3 WHERE comm IS NOT NULL 4* ORDER BY sal DESC, comm DESC;</p><p>ENAME SAL COMM 4</p><p>------ALLEN 1600 300 TURNER 1500 0 MARTIN 1250 1400 WARD 1250 500 </p><p>SQL> --√ 10. Display the names of all employees where the third SQL> -- letter of their name is an A. SQL> SQL> SELECT ename 2 FROM EMP 3 WHERE ename LIKE '__A%';</p><p>ENAME ------BLAKE CLARK ADAMS </p><p>SQL> SQL> --√ 11. Display the name of all employees who have two Ls in their SQL> -- name and are in department 30 or their manager is 7782. SQL> SQL> SELECT ename 2 FROM EMP 3 WHERE ename LIKE '%L%L%' AND deptno = 30 OR mgr = 7782;</p><p>ENAME ------ALLEN MILLER </p><p>SQL> --√ 12. Display the name, job, and salary for all employees whose job SQL> -- is Clerk or Analyst and their salary is not equal to $1000, SQL> -- $3000, or $5000. SQL> SQL> SELECT ename, job, sal 2 FROM EMP 3* WHERE job IN ('CLERK', 'ANALYST') AND sal NOT IN (1000,3000,5000);</p><p>ENAME JOB SAL ------SMITH CLERK 800 ADAMS CLERK 1100 JAMES CLERK 950 MILLER CLERK 1300 </p><p>SQL> --√ 13. Modify p2q6.sal to display the name, salary, and commission SQL> -- for all employees whose commission amount is greater than their SQL> -- salary increased by 10%. Rerun your query. Resave your query SQL> -- as p2q13.sql. SQL> SQL> edit p2q6.sql 5</p><p>SQL> get p2q13.sql 1 SELECT ename AS "Employee", sal AS "Monthly Salary", comm AS "Commission" 2 FROM EMP 3* WHERE comm > (sal + sal * .10) SQL> /</p><p>Employee Monthly Salary COMMISSION ------MARTIN 1250 1400 </p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us