daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 60 in 2 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Первая часть. Все хорошо
  2. select r.name as "region", c.ID from s_ord s
  3. left join s_customer c on c.id = s.CUSTOMER_ID
  4. left join s_region r on r.id = c.region_id
  5. where region_id in (select region_id from (
  6. select c.region_id, count(*) cnt from s_ord s
  7.   left join s_customer c on c.id = s.CUSTOMER_ID
  8.   group by c.region_id)
  9.   where cnt =
  10.   (select max(cnt)
  11.   from (
  12.     select c.region_id, count(*) cnt from s_ord s
  13.     left join s_customer c on c.id = s.CUSTOMER_ID
  14.     group by c.region_id)))
  15.     group by r.name, c.id
  16.  
  17. #Вторая часть
  18.  
  19. select e.ID, e.DEPT_ID, count(*) sales
  20. from s_emp e
  21. right join s_ord o on o.SALES_REP_ID = e.ID
  22. where e.ID is not null
  23. and e.ID in (
  24.     select id from (
  25.       select d.id, count(*) cnt from s_dept d
  26.       left join s_emp e on e.DEPT_ID = d.ID
  27.       group by d.id) t
  28.     where  cnt = (select min(count(*)) from s_dept d
  29.     left join s_emp e on e.DEPT_ID = d.ID
  30.     group by d.id)
  31. )
  32. group by e.ID, e.DEPT_ID
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top