1

Topic: How to optimize this request?

There is a request

select sf.whs_id as ID, sum (sf.frcst_sum) as frcst_sum, days.month_id, sf.calc_dt as data_zagruzki from PRD_VD_DM.V_WHS_FRCST_OPSUM sf
inner join PRD_VD_DM.V_days DAYS on sf.day_id=days.day_id
and sf.calc_dt = (select max (calc_dt) from PRD_VD_DM.V_WHS_FRCST_OPSUM sf1 where sf1.whs_id=sf.whs_id and sf1.day_id=sf.day_id)
and days.month_id=201708
where sf.whs_id in (29049)
group by sf.whs_id,days.month_id,sf.frcst_sum,sf.calc_dt

It produces ID object, ID month, Date of the last loading of the data (in  it is a lot of loading dates), the total for a day, and day
As in a picture. How to rewrite request without using  sf two times? To replace a line

and sf.calc_dt = (select max (calc_dt) from PRD_VD_DM.V_WHS_FRCST_OPSUM sf1 where sf1.whs_id=sf.whs_id and sf1.day_id=sf.day_id)

2

Re: How to optimize this request?

Romanov-krd,

3

Re: How to optimize this request?

Romanov-krd;
Top 1 with ties in sorting on Row_number