161 auth_session_ls
This commit is contained in:
+15
-10
@@ -38,7 +38,7 @@ select dayscale.dt
|
||||
,sum (o.cost/dayscale.monthdays*o.probability_pc/100) as sum_unbounded
|
||||
,sum(
|
||||
case when (o.dt_to > dayscale.dt /*OR o.dt_to IS NULL*/) then
|
||||
o.cost*COALESCE(
|
||||
o.cost*o.quantity*(100 - coalesce(o.discount,0)/100)*COALESCE(
|
||||
case when o.agreement_is_actual then 100 else o.probability_pc end
|
||||
,0)/100/dayscale.monthdays
|
||||
else 0
|
||||
@@ -46,23 +46,23 @@ select dayscale.dt
|
||||
) as sum_working
|
||||
,sum(
|
||||
case when (o.dt_to_base > dayscale.dt /*OR o.dt_to_base IS NULL*/) then 0 else
|
||||
o.cost_base*(100-COALESCE(
|
||||
o.cost_base*o.quantity_base*(100 - coalesce(o.discount_base,0)/100)*(100 - COALESCE(
|
||||
case when o.agreement_is_actual then 100 else o.probability_pc end
|
||||
,0))/100/dayscale.monthdays
|
||||
end
|
||||
) as sum_base
|
||||
,sum(
|
||||
COALESCE(case when (o.dt_to > dayscale.dt /*OR o.dt_to IS NULL*/) then
|
||||
o.cost*(
|
||||
o.cost*o.quantity*(100 - coalesce(o.discount,0)/100)*(
|
||||
case when o.agreement_is_actual then 100 else o.probability_pc end
|
||||
)/100/dayscale.monthdays
|
||||
else 0 /*по окончании рабочей сделки она дает нулевой вклад*/
|
||||
end,0)
|
||||
+
|
||||
COALESCE(case when (o.dt_to_base > dayscale.dt /*OR o.dt_to_base IS NULL*/) then
|
||||
o.cost_base/dayscale.monthdays*(100- COALESCE(
|
||||
o.cost_base*o.quantity_base*(100 - coalesce(o.discount_base,0)/100)*(100 - COALESCE(
|
||||
case when o.agreement_is_actual then 100 else o.probability_pc end
|
||||
,0))/100
|
||||
,0))/100/dayscale.monthdays
|
||||
else 0 /*по окончании базовой сделки она дает нулевой вклад*/
|
||||
end,0)
|
||||
) as sum_bounded
|
||||
@@ -88,19 +88,24 @@ LEFT OUTER JOIN (
|
||||
FROM line where siv_is_actual AND probability_pc=100 AND agreement_is_actual AND deal_status_id in (5,6)
|
||||
) i where i.dt_from=i.running_min_dt
|
||||
) b on (t.line_key=b.line_key AND b.siv_uid=(
|
||||
select siv_uid from
|
||||
select siv_uid from
|
||||
( -- базовая лесенка
|
||||
SELECT siv_uid, dt_from, agreement_version, line_version,
|
||||
SELECT siv_uid, dt_from, agreement_version, line_version, line_key,
|
||||
MIN(dt_from) OVER (PARTITION BY line_key ORDER BY agreement_version desc, line_version desc) running_min_dt
|
||||
FROM line where siv_is_actual AND probability_pc=100 AND agreement_is_actual AND deal_status_id in (5,6)
|
||||
) i where i.dt_from=i.running_min_dt
|
||||
AND i.dt_from < t.dt_from
|
||||
FROM line ii
|
||||
where ii.siv_is_actual AND ii.probability_pc=100 AND ii.agreement_is_actual AND ii.deal_status_id in (5,6)
|
||||
AND ((t.agreement_version > ii.agreement_version) OR (t.agreement_version = ii.agreement_version AND t.line_version > ii.line_version))
|
||||
) i
|
||||
where i.dt_from=i.running_min_dt
|
||||
AND t.line_key=i.line_key
|
||||
AND i.dt_from < t.dt_from
|
||||
ORDER BY /*dt_from desc,*/ agreement_version desc, line_version desc
|
||||
LIMIT 1
|
||||
)
|
||||
)
|
||||
where t.dt_from=t.running_min_dt -- это условие формирования лесенки, далко оторвано от ее селекта
|
||||
AND t.line_pricing_model_id in (2,3)
|
||||
AND t.probability_pc > 0 -- несколько искусственное условие, убирающее несущественные и неуспешные сделки
|
||||
|
||||
--AND t.line_key in ('0a61f9e4-520b-4f0a-aac0-c1d42c037e1b','0bde160d-52d0-4d55-b4e0-05f45cfd739e','08485a0c-a913-4332-bb36-e40dec27d12e','1809bb31-4d37-424b-ba2b-26b9a873af7f')
|
||||
) o
|
||||
|
||||
Reference in New Issue
Block a user