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 8280729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:47:15+00:00 2026-06-08T09:47:15+00:00

Im tring to get in one query how many items price higher than average

  • 0

Im tring to get in one query how many items price higher than average price and lower.

My query:

SELECT COUNT(*)
FROM item i
WHERE refine = 0 AND item = 5170
GROUP BY id
HAVING price > AVG(price) - STD(price) AND i.price < AVG(price) + STD(price)

But i get error Unknown column ‘price’ in ‘having clause’

If I’m using AVG and STD functions in SELECT:

SELECT COUNT(*), SUM(price > AVG(price) - STD(price) AND i.price < AVG(price) + STD(price)) as middle
FROM item i
WHERE refine = 0 AND item = 5170

I get error again. How make correct query?

Here link on sqlFiddle

  • 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-08T09:47:16+00:00Added an answer on June 8, 2026 at 9:47 am

    Try this

    select count(*) from item as t1 inner join
    (
    select id,AVG(price) - STD(price) as sum1, AVG(price) + STD(price)  as sum2
    from item 
    group by id
    ) as t2
    on t1.id=t2.id and t1.price>sum1 and t1.price<sum2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get one object from this array and print all of its
I'm trying to get a one-to-many relationship working with grails/gorm. I don't understand how
I'm trying to get content from an RSS2 feed from one of my sites
I am trying to do a mysql query to select some news stories from
I'm trying to get an average for a count on a groupBy by joining
How to do this on Google App Engine (Python): SELECT COUNT(DISTINCT user) FROM event
I am tring to query a set of data from mySQL with the following
This is a follow up question to this one: Query examples in a many-to-many
I've got several function where I need to do a one-to-many join, using count(),
We all know that it's better to use multiple inserts in ONE query than

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.