Advertisement
CSenshi

DB ESM - HW1.2

May 17th, 2020
1,604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.72 KB | None | 0 0
  1. SELECT
  2.   in_t.mon as MONTH,
  3.   in_t.dep as DEPARTMENT,
  4.   TO_CHAR(MAX(in_t.salary), 'fm$999,999,990.00') as MAX_SALARY,
  5.   TO_CHAR(MIN(in_t.salary), 'fm$999,999,990.00') as MIN_SALARY,
  6.   avg(case when in_t.job_id like '%MAN' then in_t.salary else null end) MNG_AVG_SALARY,
  7.   count(distinct in_t.department_id) as DEP_COUNT
  8. FROM
  9.   (SELECT
  10.       TO_CHAR(e.hire_date, 'Mon') AS mon,
  11.       (CASE WHEN e.department_id = 50 THEN 'Shipping' ELSE 'Other' END) as dep,
  12.       e.job_id,
  13.       e.department_id,
  14.       e.salary
  15.     FROM hr.employees e) in_t
  16. GROUP BY
  17.   in_t.dep,
  18.   in_t.mon
  19.  HAVING
  20.   count(case when in_t.job_id like '%MAN' then 1 else null end) > 0
  21. ORDER BY
  22.   in_t.dep DESC,
  23.   TO_DATE(in_t.mon, 'Mon');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement