Please use following table information to answer the exercises. SQL> DESC DEPARTMENTS Name Null? Type ----------------------------------------- -------- ---------------------------- DEPARTMENT_ID NOT NULL NUMBER(4) DEPARTMENT_NAME NOT NULL VARCHAR2(30) MANAGER_ID NUMBER(6) LOCATION_ID NUMBER(4) SQL> DESC EMPLOYEES Name Null? Type ----------------------------------------- -------- ---------------------------- EMPLOYEE_ID NOT NULL NUMBER(6) FIRST_NAME VARCHAR2(20) LAST_NAME NOT NULL VARCHAR2(25) EMAIL NOT NULL VARCHAR2(25) PHONE_NUMBER VARCHAR2(20) HIRE_DATE NOT NULL DATE JOB_ID NOT NULL VARCHAR2(10) SALARY NUMBER(8,2) COMMISSION_PCT NUMBER(2,2) MANAGER_ID NUMBER(6) DEPARTMENT_ID NUMBER(4) Display the last name, hire date, and day of the week on which the employee started. Label the column DAY. Order the results by the week starting with Monday. 16. Display first name and last name of employees who were hired before 2010. 17. What is the last day of the current month?
SQL> DESC DEPARTMENTS
Name Null? Type
----------------------------------------- -------- ----------------------------
DEPARTMENT_ID NOT NULL NUMBER(4)
DEPARTMENT_NAME NOT NULL VARCHAR2(30)
MANAGER_ID NUMBER(6)
LOCATION_ID NUMBER(4)
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPLOYEE_ID NOT NULL NUMBER(6)
FIRST_NAME VARCHAR2(20)
LAST_NAME NOT NULL VARCHAR2(25)
EMAIL NOT NULL VARCHAR2(25)
PHONE_NUMBER VARCHAR2(20)
HIRE_DATE NOT NULL DATE
JOB_ID NOT NULL VARCHAR2(10)
SALARY NUMBER(8,2)
COMMISSION_PCT NUMBER(2,2)
MANAGER_ID NUMBER(6)
DEPARTMENT_ID NUMBER(4)
DAY. Order the results by the week starting with Monday.
16. Display first name and last name of employees who were hired before 2010.
17. What is the last day of the current month?
- Display first name and last name of employees who were hired before 2010:
Display the last name, hire date, and day of the week on which the employee started. Label the column DAY. Order the results by the week starting with Monday.
To display the last name, hire date, and day of the week, you would use the following query:
SELECT LAST_NAME, HIRE_DATE, TO_CHAR(HIRE_DATE, 'DAY') AS DAY
FROM EMPLOYEES;
The TO_CHAR function is used to format the HIRE_DATE column into a string representation of the day of the week. The AS DAY clause is used to label the resulting column as DAY.
To order the results by the week starting with Monday, you would use the following query:
SELECT LAST_NAME, HIRE_DATE, TO_CHAR(HIRE_DATE, 'DAY') AS DAY
FROM EMPLOYEES
ORDER BY TO_CHAR(HIRE_DATE, 'D');
The ORDER BY clause is used to sort the results. The TO_CHAR function is used again to format the HIRE_DATE column into a string representation of the day of the week, but this time with the format model 'D' which gives the number of the day of the week (where Monday = 1 and Sunday = 7).
Trending now
This is a popular solution!
Step by step
Solved in 2 steps