Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --with wv as (select distinct(t.wave) as w from ma_metro.tasks t where t.wave in (?))
- with wv(w) as (values(ARRAY['m54_2918_reg','m54_2918_oif'])),
- gobj(g) as (values(ARRAY[282,284]))
- select
- --wwv.w "какие волны" ,
- accepted_q+pq "колво ску, для которых есть неотклоненные отчеты по второй"
- , accepted_q "уникальные ску для которых есть принятый по второй"
- , case when cjc.cjqс>0 then cjc.cjqс else jc.jqc end "джобов сделанных"
- , case when cjp.cjqp>0 then cjp.cjqp else jp.jqp end "джобов надо сделать"
- , 0 as "товаров к распу" , 0 as "ску в тасках имеющ резерв"
- , aq "ску в тасках, которые есть на системе"
- , date_trunc('minute', now()) "когда выполнен запрос"
- , 60 as "айди запроса"
- from (select 1 clue, count (distinct ai) aq
- from (select concat(t.geo_object_id, unnest(t.active_article_ids::int[])) ai
- from wv, gobj, ma_metro.tasks t
- where t.wave=any(w) and t.geo_object_id=any(g)) as a) as b
- left outer join (select 1 clue, r.state, count(distinct concat(t.geo_object_id, r.article_id)) pq
- from wv, gobj, ma_metro.reports r join ma_metro.tasks t on r.task_id=t.id
- 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
- (select 1 from wv, gobj, ma_metro.reports ra join ma_metro.tasks t on ra.task_id=t.id
- 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
- using (clue)
- left outer join (select 1 clue, count(distinct concat(t.geo_object_id, r.article_id)) accepted_q
- from wv, gobj, ma_metro.reports r join ma_metro.tasks t on r.task_id=t.id
- 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
- using (clue)
- left outer join (select 1 clue, count(*) cjqс
- 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
- where j.state='completed' and j.wave=any(w) and t.geo_object_id=any(g) group by clue) cjc
- using(clue)
- left outer join (select 1 clue, count(*) cjqp
- 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
- where j.state='acitve' and j.wave=any(w) group by clue) cjp
- using(clue)
- left outer join (select 1 clue, count(*) jqc
- from wv, gobj, ma_metro.reports r join ma_metro.tasks t on t.id=r.task_id
- 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
- using (clue)
- left outer join (select 1 clue, count(*) jqp
- from wv, gobj, ma_metro.reports r join ma_metro.tasks t on t.id=r.task_id
- 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
- using (clue)
- --left outer join (select 1 clue, w from wv) as wwv using (clue)
- --left outer join (select 1 clue, g from gb) as gobj using (clue)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement