MySQL: Read out Prices over or under the average Price
Question by Guest | 2016-07-12 at 23:13
In my MySQL database, I have a table in which I have saved my products and the corresponding prices.
Now, I would like to create a MySQL query returning all products that are either listed over or under the average or mean price of all products in my query or database.
I am still feasible to calculate the average, however, I do not know how to put this into the query. Can someone help me?
Related Topics
Stock Exchange: Order Supplements when Selling Securities
Info | 0 Comments
Rewrite Text Files with a fixed Line Length
Tutorial | 0 Comments
Stock Exchange: Order Supplements when Buying Securities
Info | 0 Comments
MySQL: Change minimum word length for full text search
Tip | 1 Comment
Why are there fixed book prices in Germany?
Question | 3 Answers
jQuery: Read and Change Data Attribute Value
Tutorial | 0 Comments
Stock Exchange: Bid, Ask and Spread
Info | 0 Comments
Important Note
Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.
Participate
Ask your own question or write your own article on askingbox.com. That’s how it’s done.
You can just calculate the average price using "SELECT AVG(price) FROM products".
After that, you only have to compare the price of each product with this calculated average:
With this, you are reading out all prices lying over the average. If you want to get the prices under the average instead, you have to replace the > with a < to make it work.
2016-07-13 at 08:08