Answers to SQL problems
-
SELECT LOWER(email) || '@hr.co.uk' FROM employees;
-
SELECT 'Salaries in the company range from $' || TO_CHAR(MIN(salary)) || ' to $' || TO_CHAR(MAX(salary)) || ' per month' FROM employees;
-
SELECT last_name || ', ' || SUBSTR(first_name,1,1) AS name FROM employees WHERE job_id = 'IT_PROG' ORDER BY name;
-
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id;
-
SELECT department_id, ROUND(AVG(salary)/1000,1) AS "Average salary" FROM employees GROUP BY department_id;
-
SELECT job_title, min_salary, max_salary, max_salary-min_salary AS Range FROM jobs;
-
SELECT job_title, min_salary, max_salary, max_salary-min_salary AS Range FROM jobs ORDER BY Range DESC;
-
SELECT TO_CHAR(hire_date,'YYYY') AS Hired, COUNT(*) AS "New employees" FROM employees GROUP BY to_char(hire_date,'YYYY') ORDER BY Hired;
-
SELECT last_name, NVL(department_id,0) AS Dept FROM employees WHERE job_id = 'SA_REP';
-
SELECT last_name, NVL(TO_CHAR(department_id),'No dept id') AS Dept FROM employees WHERE job_id = 'SA_REP';