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

  • SEARCH
  • Home
  • 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 8067969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:30:30+00:00 2026-06-05T12:30:30+00:00

I have a query that returns avg(price) select avg(price) from( select *, cume_dist() OVER

  • 0

I have a query that returns avg(price)

  select avg(price)
  from(
      select *, cume_dist() OVER (ORDER BY price desc) from web_price_scan
      where listing_Type='AARM'
        and u_kbalikepartnumbers_id = 1000307
        and (EXTRACT(Day FROM (Now()-dateEnded)))*24 < 48
        and price>( select avg(price)* 0.50
                    from(select *, cume_dist() OVER (ORDER BY price desc)
                         from web_price_scan
                         where listing_Type='AARM'
                           and u_kbalikepartnumbers_id = 1000307
                           and (EXTRACT(Day FROM (Now()-dateEnded)))*24 < 48
                        )g
                   where cume_dist < 0.50
                 )
        and price<( select avg(price)*2
                    from( select *, cume_dist() OVER (ORDER BY price desc)
                          from web_price_scan
                          where listing_Type='AARM'
                            and u_kbalikepartnumbers_id = 1000307
                            and (EXTRACT(Day FROM (Now()-dateEnded)))*24 < 48
                        )d
                    where cume_dist < 0.50)
     )s

  having count(*) > 5

how to make it return 0 if no value is available?

  • 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-06-05T12:30:32+00:00Added an answer on June 5, 2026 at 12:30 pm

    use coalesce

    COALESCE(value [, ...])
    
    The COALESCE function returns the first of its arguments that is not null.  
    Null is returned only if all arguments are null. It is often
    used to substitute a default value for null values when data is
    retrieved for display.
    

    Edit

    Here’s an example of COALESCE with your query:

    SELECT AVG( price )
    FROM(
          SELECT *, cume_dist() OVER ( ORDER BY price DESC ) FROM web_price_scan
          WHERE listing_Type = 'AARM'
            AND u_kbalikepartnumbers_id = 1000307
            AND ( EXTRACT( DAY FROM ( NOW() - dateEnded ) ) ) * 24 < 48
            AND COALESCE( price, 0 ) > ( SELECT AVG( COALESCE( price, 0 ) )* 0.50
                                         FROM ( SELECT *, cume_dist() OVER ( ORDER BY price DESC )
                                               FROM web_price_scan
                                               WHERE listing_Type='AARM'
                                                 AND u_kbalikepartnumbers_id = 1000307
                                                 AND ( EXTRACT( DAY FROM ( NOW() - dateEnded ) ) ) * 24 < 48
                                             ) g
                                        WHERE cume_dist < 0.50
                                      )
            AND COALESCE( price, 0 ) < ( SELECT AVG( COALESCE( price, 0 ) ) *2
                                         FROM( SELECT *, cume_dist() OVER ( ORDER BY price desc )
                                               FROM web_price_scan
                                               WHERE listing_Type='AARM'
                                                 AND u_kbalikepartnumbers_id = 1000307
                                                 AND ( EXTRACT( DAY FROM ( NOW() - dateEnded ) ) ) * 24 < 48
                                             ) d
                                         WHERE cume_dist < 0.50)
         )s
    HAVING COUNT(*) > 5
    

    IMHO COALESCE should not be use with AVG because it modifies the value. NULL means unknown and nothing else. It’s not like using it in SUM. In this example, if we replace AVG by SUM, the result is not distorted. Adding 0 to a sum doesn’t hurt anyone but calculating an average with 0 for the unknown values, you don’t get the real average.

    In that case, I would add price IS NOT NULL in WHERE clause to avoid these unknown values.

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

Sidebar

Related Questions

I have a query that returns all stream posts from users (with comments): SELECT
I have following SQL query that selects some results from my table: select avg(c3),
I have a query, that returns all entries, with unique datetime with ticks: select
I have a query that returns 2 columns from joining 2 entities as the
I have a query that returns all posts from a DB table that match
I have following query which has select query that returns data in 5sec. But
I have this query that returns the results by ordering it by focus.name ASC.
I have a query that returns me around 6 million rows, which is too
I have a query that returns Properties for Rent / Sale on their respective
I have a query that returns a result set similar to the one below:

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.