Oracle 12c Sql Hands-on - Assignments Solutions

SELECT first_name, last_name, hire_date, TRUNC(MONTHS_BETWEEN(SYSDATE, hire_date) / 12) AS years, TRUNC(MOD(MONTHS_BETWEEN(SYSDATE, hire_date), 12)) AS months, TRUNC(MONTHS_BETWEEN(SYSDATE, hire_date) / 12) || ' years, ' || TRUNC(MOD(MONTHS_BETWEEN(SYSDATE, hire_date), 12)) || ' months' AS tenure FROM employees; Mask email addresses for a report (Show first 2 letters, then ' ** ', then the domain 'oracle.com').

12 minutes Introduction Oracle 12c introduced several game-changing features, such as Top-N Row limiting (the FETCH FIRST clause) and improved Visibility into Partitioned Tables . However, the core of database mastery still lies in solving real-world problems.

CREATE TABLE emp_analytics AS SELECT department_id, last_name, salary, RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS salary_rank FROM employees; Oracle 12c SQL is robust, but the secret to passing hands-on assignments is understanding the subtle differences in windowing functions and the modern Top-N syntax . Always test your OFFSET/FETCH logic on a small subset first to verify sorting order. oracle 12c sql hands-on assignments solutions

SELECT employee_id, first_name, last_name, salary FROM employees ORDER BY salary DESC FETCH FIRST 5 ROWS WITH TIES; Note: Without WITH TIES , it returns exactly 5 rows. With WITH TIES , it respects the salary rank.

SELECT d.department_name, l.city, COUNT(e.employee_id) AS employee_count FROM departments d LEFT JOIN employees e ON d.department_id = e.department_id LEFT JOIN locations l ON d.location_id = l.location_id GROUP BY d.department_name, l.city ORDER BY employee_count DESC; List employees who earn more than the average salary of their own department. With WITH TIES , it respects the salary rank

Oracle 12c, SQL, Assignments, PL/SQL, Window Functions

SELECT email, SUBSTR(email, 1, 2) || '****@oracle.com' AS masked_email FROM employees; Problem 9: Rank employees within each department by salary. Show rank, dense rank, and row number. and row number. SELECT employee_id

SELECT employee_id, first_name, last_name, hire_date FROM employees ORDER BY hire_date OFFSET 20 ROWS FETCH NEXT 10 ROWS ONLY; Problem 7: Calculate the exact number of months and years each employee has worked as of today's date. Output format: "14 years, 3 months".