Hello Members, Please I'm stuck in an SQL query and I need your help. I have a list of people who are in arears for rent. Now, I have a query that distinctively retrieves those in arrears as shown below. Apart from the query being distinctive, I want two other conditions to be met. 1. I want those in arrears for a certain numbers of years (e.g. 5) be retrieved and 2. I want to search for those in arrears for a certain amount (e.g. 500) So the code below only distinctively retrieves those who are in arrears less than the current year and I want those in arrears for a certain number of years e.g. 5 years and those in arears for a certain amount when entered. Thanks.
Select from(select , row_number() over (partition by FileNo order by EndDate Desc) as row_number from RentPayment) as rows where row_number=1 And StartYear < @CurrentYear