Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. --with wv as (select distinct(t.wave) as w from ma_metro.tasks t where t.wave in (?))
  2. with wv(w) as (values(ARRAY['m54_2918_reg','m54_2918_oif'])),
  3. gobj(g) as (values(ARRAY[282,284]))
  4. select
  5. --wwv.w "какие волны" ,
  6. accepted_q+pq "колво ску, для которых есть неотклоненные отчеты по второй"
  7. , accepted_q "уникальные ску для которых есть принятый по второй"
  8. , case when cjc.cjqс>0 then cjc.cjqс else jc.jqc end "джобов сделанных"
  9. , case when cjp.cjqp>0 then cjp.cjqp else jp.jqp end "джобов надо сделать"
  10. , 0 as "товаров к распу" , 0 as "ску в тасках имеющ резерв"
  11. , aq "ску в тасках, которые есть на системе"
  12. , date_trunc('minute', now()) "когда выполнен запрос"
  13. , 60 as "айди запроса"
  14. from (select 1 clue, count (distinct ai) aq
  15. from (select concat(t.geo_object_id, unnest(t.active_article_ids::int[])) ai
  16. from wv, gobj, ma_metro.tasks t
  17. where t.wave=any(w) and t.geo_object_id=any(g)) as a) as b
  18. left outer join (select 1 clue, r.state, count(distinct concat(t.geo_object_id, r.article_id)) pq
  19. from wv, gobj, ma_metro.reports r join ma_metro.tasks t on r.task_id=t.id
  20. where t.wave=any(w) and t.geo_object_id=any(g) and project_id=2 and r.state in ('pending', 'on_verification') and not exists
  21. (select 1 from wv, gobj, ma_metro.reports ra join ma_metro.tasks t on ra.task_id=t.id
  22. where t.wave=any(w) and t.geo_object_id =any(g) and project_id=2 and r.state='accepted' and r.id=ra.id) group by r.state) as oq
  23. using (clue)
  24. left outer join (select 1 clue, count(distinct concat(t.geo_object_id, r.article_id)) accepted_q
  25. from wv, gobj, ma_metro.reports r join ma_metro.tasks t on r.task_id=t.id
  26. where t.wave=any(w) and t.geo_object_id=any(g) and project_id=2 and r.state ='accepted' group by r.state) aq
  27. using (clue)
  28. left outer join (select 1 clue, count(*) cjqс
  29. from wv, gobj, ma_metro.conveyor_jobs j join ma_metro.reports r on j.target_id=r.id join ma_metro.tasks t on t.id=r.origin_report_id
  30. where j.state='completed' and j.wave=any(w) and t.geo_object_id=any(g) group by clue) cjc
  31. using(clue)
  32. left outer join (select 1 clue, count(*) cjqp
  33. from wv, gobj, ma_metro.conveyor_jobs j join ma_metro.reports r on j.target_id=r.id join ma_metro.tasks t on t.id=r.origin_report_id
  34. where j.state='acitve' and j.wave=any(w) group by clue) cjp
  35. using(clue)
  36. left outer join (select 1 clue, count(*) jqc
  37. from wv, gobj, ma_metro.reports r join ma_metro.tasks t on t.id=r.task_id
  38. where t.project_id=2 and t.wave=any(w) and t.geo_object_id=any(g) and r.state in ('accepted','invalid_article','invalid_availability','poor_quality_photo','rejected')) as jc
  39. using (clue)
  40. left outer join (select 1 clue, count(*) jqp
  41. from wv, gobj, ma_metro.reports r join ma_metro.tasks t on t.id=r.task_id
  42. where t.project_id=2 and t.wave=any(w) and t.geo_object_id=any(g) and r.state in ('pending','on_verification')) as jp
  43. using (clue)
  44. --left outer join (select 1 clue, w from wv) as wwv using (clue)
  45. --left outer join (select 1 clue, g from gb) as gobj using (clue)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement