Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 612537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:54:16+00:00 2026-05-13T17:54:16+00:00

I am displaying a property from the following table given below. Now what i

  • 0

I am displaying a property from the following table given below. Now what i have to do is, find the property in the same location(suppose my property is located in sec-19, match for sec-19 and if none of them found there then search for the entire city) with the following condition that it should be posted 10 days back or if none is posted 10 days back than take result on the basis of 30 days back.

I have the following table(Properties) mentioned below:

ID|Propertyid|Userid|Projectid|..|Price|...|Listing time|...

Now what i want to retrieve 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 for less than 30 days.

Can anybody help me solving this problem. Thanks in advance.

Or just Any body can answer me without the Location match.

I need to calculate ‘Average Price’ from the properties posted 10 days ago, if there is no property posted 10 days ago then take it as 30 days ago. Something like this:

Select AVG(Price) As Average_Price from Properties where (DATEDIFF(day,listingtime,getdate())<30 or DATEDIFF(day,listingtime,getdate())<10)

But here i am getting only one Field ‘Average Price’ and here also i am not putting the check to filter whether it has been posted 10 days ago or 30 days ago. Knidly Recheck and try to solve my problem. Thanks in Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:54:17+00:00Added an answer on May 13, 2026 at 5:54 pm

    I spent some time on this and I believe I addressed all of your concerns. I wasn’t completely sure of the datatypes of city or location so I used varchar(100) This should address all of your concerns. Please comment if there is a situation that you described that this doesn’t solve.

       CREATE PROCEDURE [dbo].[GetRecentlyListedProperties]
    (@location varchar(100), @city varchar(100),@propertyID int)
    As
    Begin
    DECLARE @numberOfDays int,
            @propertyCount int, 
            @IsLocation bit -- looking for a location and not a city    
    SET @Propertycount = 0
    SET @numberOfDays= 10 
    -- CHECK TO SEE IF THERE ARE LISTINGS IN THE LAST 10 DAYS IN THE SAME LOCATION
    SELECT  @PropertyCount = 
     Count(*) FROM properties where location = @location and DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
     and PropertyID != @propertyID
    If(@PropertyCount = 0)
    Begin
    -- CHECK TO SEE IF THERE ARE LISTINGS IN THE LAST 10 DAYS IN THE SAME CITY
    SELECT  @PropertyCount = Count(*) from properties where city = @city 
            AND DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
            AND PropertyID != @propertyID   
        IF(@PropertyCount = 0 )
        BEGIN
        SET @NumberOfDays = 30
        -- CHECK TO SEE IF THERE ARE LISTINGS IN THE LAST 30 DAYS IN THE SAME LOCATION
        SELECT  @PropertyCount = COUNT(*) from properties where location = @location 
                AND DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
                AND PropertyID != @propertyID
            IF(@PropertyCount = 0 )
            BEGIN
            -- CHECK TO SEE IF THERE ARE LISTINGS IN THE LAST 30 DAYS IN THE SAME CITY
            SELECT @PropertyCount = Count(*) from properties where city = @city 
                    AND DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
                    AND PropertyID != @propertyID
            END
            ELSE
            SET @IsLocation = 1 --There are properties in the same location in the last 30 days
        END
        ELSE
        SET @IsLocation  = 0 -- There are properties listed int he city in the last 10 days
    End
    Else
    SET @IsLocation = 1
    -- This is where the appropriate results are returned. 
    IF(@IsLocation = 1)
    Begin
    SELECT * ,(SELECT AVG(PRICE) as AveragePrice
           FROM PROPERTIES 
           WHERE DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
             AND Location = @Location
             AND PropertyID != @propertyID)
    FROM Properties 
    WHERE DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
          AND Location = @Location
          AND PropertyID != @propertyID
    End
    ElSE
    SELECT * ,(SELECT AVG(PRICE) as AveragePrice
          FROM PROPERTIES 
              WHERE DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
              AND City = @City
              AND PropertyID != @propertyID)
    FROM Properties 
    WHERE DATEDIFF(day,listingtime,GETDATE()) < @numberOFDays
          AND City = @City 
          AND PropertyID != @propertyID
    End
    

    You may have to change some datatypes for foreign keys for location and city as I used them as varchars.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table displaying some data from a table in a ctp file. I
I have a UITableView displaying a set of options from which the user will
I'm displaying all of my customers which I get from a ViewModel ObservableCollectoin property
I have a view displaying data from a model. My model contains a string
I have a table displaying a tree structure (Super- and Subcategories). When the user
I have another rather curious problem. I have the following structure: CREATE TABLE [dbo].[Event]
I have a problem with updating the value of property from code which is
I'm displaying data from an XML file (simplified below) with an mx:Tree class in
When displaying all articles of a specific month (given through the urls like this
For displaying data in our application I've use GridView with the following markup: <asp:GridView

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.