Generate sales sheet data SQL
WITH RankedRows AS (
select strdc,strcarriercode,strreference,dtmdep,case when dayofweek(dtmdep) = 2 then 1
when dayofweek(dtmdep) = 3 then 2
when dayofweek(dtmdep) = 4 then 3
when dayofweek(dtmdep) = 5 then 4
when dayofweek(dtmdep) = 6 then 5
when dayofweek(dtmdep) = 7 then 6
when dayofweek(dtmdep) = 1 then 7 end as weekday,strcontractcode,strdep,strdes,(select cp.strcontractprofilecode
from contractline cp
where
cp.strcode=strContractCode),intfxcap, (select pc.fltamount
from pricecomponent pc where
pc.strrefkey=strContractCode and dtmdep=pc.dtmdepfrom), ROW_NUMBER() OVER (PARTITION BY strdc, strreference, dtmdep, strcontractprofilecode ORDER BY intversion DESC) AS RowNum
FROM flightallotmenth where lngfkid in (
-- lngfk goes here --
) and dtmmod<'2024-02-01 09:30:00' )
SELECT * FROM
RankedRows
WHERE
RowNum = 1;