I show the property from the following table below. Now, what I need to do is find the property in the same place (suppose my property is in second 19, match with second 19 and, if none of them are found there, then look for the whole city) with the following condition that it should be sent 10 days ago, or if none was published 10 days ago, then the result will be received based on 30 days ago.
I have the following table (Properties) mentioned below:

Now, what I want to extract from this table is the 'Propertyid' and 'Average Price' of those properties whose listing time is less than 10 days, if none of them are less than 10 days, then return the result in less than 30 days.
Can anyone help me solve this problem. Thank you in advance.
Or just any body can answer me without matching the location.
I need to calculate the "average price" for properties published 10 days ago, if there is no property published 10 days ago, then take it as 30 days ago. Something like that:
Select AVG(Price) As Average_Price from Properties where (DATEDIFF(day,listingtime,getdate())<30 or DATEDIFF(day,listingtime,getdate())<10)
But here I get only one field "Average price", and here I also do not put a check to filter whether it was published 10 days ago or 30 days ago. Double-check and try to solve my problem. Thank you in advance.
Sanju source
share