Oracle 12c, SQL, Assignments, PL/SQL, Window Functions
WHERE TO_CHAR(hire_date, 'YYYY') = '2012'; Find all products in the oe.product_information table whose list price is between $50 and $200, but exclude products where the product name contains the word 'Monitor'.
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. oracle 12c sql hands-on assignments solutions
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".
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. Oracle 12c, SQL, Assignments, PL/SQL, Window Functions WHERE
SELECT employee_id, first_name, last_name, hire_date FROM employees WHERE EXTRACT(YEAR FROM hire_date) = 2012 ORDER BY hire_date ASC; You can also use the TO_CHAR method:
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'). With WITH TIES , it respects the salary rank
SELECT department_id, last_name, salary, RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS rank, DENSE_RANK() OVER (PARTITION BY department_id ORDER BY salary DESC) AS dense_rank, ROW_NUMBER() OVER (PARTITION BY department_id ORDER BY salary DESC) AS row_num FROM employees WHERE department_id IS NOT NULL ORDER BY department_id, salary DESC; Find the salary difference between each employee and the next highest paid employee in the same department.