I have no experience with SQL however I have a pre-exisiting query and I want to add a filter that states in-service as Y and dates between 21-Aug-21 through -11-Sep-21
See below query and screenshot
,t5 AS
(Select/+parallel(8)/ ACCT_ID,SA_ID, char_type_cd Deposit_Char,char_val Deposit_Char_Value, Quoted_Deposit_Amount,Deposit_on_Hand,START_DT Quote_Date,
(case when Deposit_on_Hand is null then Quoted_Deposit_Amount else Quoted_Deposit_Amount-Deposit_on_Hand end) Deposit_Amt_Unpaid
From (
SELECT /+parallel(8)/
SA.ACCT_ID,SA.SA_ID,sc.char_type_cd,sc.char_val, sa.tot_to_bill_amt Quoted_Deposit_Amount,sa.START_DT,
row_number() over(partition by SA.ACCT_ID order by sa.START_DT desc) Deposit_rnk,
(sum(ft.tot_amt)*(-1)) Deposit_on_Hand
from cisadm.ci_sa sa
left join cisadm.ci_ft ft on (sa.sa_id = ft.sa_id)
left join cisadm.ci_SA_Char sc on (sa.sa_id = sc.sa_id)
where SA.SA_TYPE_CD IN ('O-DEPRES', 'O-DEPCOM', 'O-EXCRDP')
AND SA.SA_STATUS_FLG IN ('20')
group by SA.ACCT_ID,SA.SA_ID,sc.char_type_cd,sc.char_val, sa.tot_to_bill_amt,sa.START_DT)
Where Deposit_Rnk=1
)