· 7 years ago · Dec 06, 2018, 10:12 AM
1drop table if exists tt_contract;
2create temp table tt_contract
3as
4select id
5from
6(
7 select c.id, row_number() over(partition by c.reg_num order by c.sign_date desc) rn
8 from spider.contract c
9 where c.sign_date between '2016-01-01' and '2016-01-15' and c.reg_num is not null
10) t;
11
12select distinct on (c.reg_num) row_number() over (order by c.sign_date) as "â„–",
13 nso.factual_address__region__kladr_code "Регион",
14 coalesce(c.customer__full_name, c.customer__short_name) as "ОрганизациÑ-заказчик",
15 c.reg_num as "РегиÑтрационный номер контракта",
16 fn.purchase_object_info as "Ðаименование контракта",
17 cp.current_contract_stage as "Ð¡Ñ‚Ð°Ð´Ð¸Ñ ÐºÐ¾Ð½Ñ‚Ñ€Ð°ÐºÑ‚Ð°",
18 c.protocol_date - fn.procedure_info__collecting__start_date as "Подача заÑвок. ДлительноÑть периода раÑÑÐ¼Ð¾Ñ‚Ñ€ÐµÐ½Ð¸Ñ Ð·Ð°Ñвок. КоличеÑтво дней между публикацией конкурÑа и Ñроком Ð¾Ð³Ð»Ð°ÑˆÐµÐ½Ð¸Ñ Ñ€ÐµÐ·ÑƒÐ»ÑŒÑ‚Ð°Ñ‚Ð¾Ð² раÑÑÐ¼Ð¾Ñ‚Ñ€ÐµÐ½Ð¸Ñ Ð·Ð°Ñвок",
19 c.price_info__price "Сумма контракта",
20 fn.procedure_info__collecting__start_date "Дата начала подачи заÑвок",
21 fn.procedure_info__collecting__end_date "Дата Ð¾ÐºÐ¾Ð½Ñ‡Ð°Ð½Ð¸Ñ Ð¿Ð¾Ð´Ð°Ñ‡Ð¸ заÑвок на уч",
22 c.protocol_date "Дата Ð¿Ð¾Ð´Ð²ÐµÐ´ÐµÐ½Ð¸Ñ Ð¸Ñ‚Ð¾Ð³Ð¾Ð² конкурÑа", -- то же, что и fn.procedure_info__scoring__date
23 c.sign_date "Дата Ð·Ð°ÐºÐ»ÑŽÑ‡ÐµÐ½Ð¸Ñ Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ€Ð°",
24 c.protocol_date "Дата Ð¿Ð¾Ð´Ð²ÐµÐ´ÐµÐ½Ð¸Ñ Ð¸Ñ‚Ð¾Ð³Ð¾Ð² закупки",
25 c.execution_period__start_date "Дата начала иÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ€Ð°",
26 c.execution_period__end_date "Дата Ð¾ÐºÐ¾Ð½Ñ‡Ð°Ð½Ð¸Ñ Ð¸ÑÐ¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ Ð´Ð¾Ð³Ð¾Ð²Ð¾Ñ€",
27 fp.publish_date "Дата Ð¾Ð³Ð»Ð°ÑˆÐµÐ½Ð¸Ñ Ñ€ÐµÐ·ÑƒÐ»ÑŒÑ‚Ð°Ñ‚Ð¾Ð² раÑÑмо",
28 fn.placing_way__name "Тип процедуры закупки"
29
30
31
32from spider.contract c
33 join spider.nsi_organization nso on nso.reg_number = c.customer__reg_num -- or c.customer__cons_registry_num = nso.cons_registry_num
34 join spider.fcs_notification fn on fn.purchase_number = c.foundation__fcs_order__order__notification_number
35 join spider.contract_procedure cp on c.reg_num = cp.reg_num
36 join tt_contract cc on cc.id = c.id
37 join spider.fcs_protocol fp on fp.purchase_number = fn.purchase_number
38 join spider.lot l on coalesce(l.lot_number,0) = coalesce(c.foundation__fcs_order__order__lot_number,0) and l.fcs_notification_id = fn.id
39 join spider.fcs_protocol_lot fpl on fpl.fcs_protocol__id = fp.id and coalesce(l.lot_number,0) = coalesce(fpl.lot_number,0)
40limit 100