22 bug fix
This commit is contained in:
+25
-10
@@ -53,8 +53,8 @@ from (
|
||||
,0 as rec0
|
||||
,count(*) as cnt
|
||||
from (SELECT dd::date as dt FROM generate_series(
|
||||
'2023-01-01'::timestamp
|
||||
,'2029-12-31'::timestamp
|
||||
'#DAYSCALE_START#'::timestamp
|
||||
,'#DAYSCALE_FINISH#'::timestamp
|
||||
,'1 day'::interval) dd
|
||||
) dayscale
|
||||
left outer join specification_item_version siv on (dayscale.dt=siv.dt_from)
|
||||
@@ -92,7 +92,7 @@ from (
|
||||
,0
|
||||
,0
|
||||
,0
|
||||
,COALESCE(sum(
|
||||
<!--- ,COALESCE(sum(
|
||||
case when (siv.dt_to > dayscale.dt OR siv.dt_to IS NULL) then
|
||||
siv.price*siv.quantity*COALESCE(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
@@ -108,12 +108,28 @@ from (
|
||||
,0))/100/dayscale.days
|
||||
/*по окончании свежей сделки*/
|
||||
end
|
||||
),0)
|
||||
),0) --->
|
||||
|
||||
,sum(
|
||||
COALESCE(case when (siv.dt_to > dayscale.dt OR siv.dt_to IS NULL) then
|
||||
siv.price*siv.quantity*(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
)/100/dayscale.monthdays
|
||||
else 0 /*по окончании рабочей сделки она дает нулевой вклад*/
|
||||
end,0)
|
||||
+
|
||||
COALESCE(case when (siv0.dt_to > dayscale.dt OR siv0.dt_to IS NULL) then
|
||||
siv0.price/dayscale.monthdays*siv0.quantity*(100- COALESCE(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
,0))/100
|
||||
else 0 /*по окончании базовой сделки она дает нулевой вклад*/
|
||||
end,0)
|
||||
)
|
||||
,sum(
|
||||
case when (siv.dt_to > dayscale.dt OR siv.dt_to IS NULL) then
|
||||
siv.price*siv.quantity*COALESCE(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
,0)/100/dayscale.days
|
||||
,0)/100/dayscale.monthdays
|
||||
else 0
|
||||
end
|
||||
)
|
||||
@@ -122,17 +138,16 @@ from (
|
||||
.dt_to IS NULL) then 0 else
|
||||
siv0.price*siv0.quantity*(100-COALESCE(
|
||||
case when a.is_actual then 100 else a.probability_perc end
|
||||
,0))/100/dayscale.days
|
||||
--else 0
|
||||
,0))/100/dayscale.monthdays
|
||||
end
|
||||
)
|
||||
,count(*)
|
||||
|
||||
from (SELECT dd::date as dt
|
||||
, DATE_PART('days', DATE_TRUNC('month', dd) + '1 MONTH'::INTERVAL - '1 DAY'::INTERVAL) days
|
||||
, DATE_PART('days', DATE_TRUNC('month', dd) + '1 MONTH'::INTERVAL - '1 DAY'::INTERVAL) monthdays
|
||||
FROM generate_series(
|
||||
'2023-01-01'::timestamp
|
||||
,'2029-12-31'::timestamp
|
||||
'#DAYSCALE_START#'::timestamp
|
||||
,'#DAYSCALE_FINISH#'::timestamp
|
||||
,'1 day'::interval) dd
|
||||
) dayscale
|
||||
left outer join specification_item_version siv on (dayscale.dt >= siv.dt_from /*AND (siv.dt_to > dayscale.dt OR siv.dt_to IS NULL)*/
|
||||
|
||||
Reference in New Issue
Block a user