MySQL Average of column where there are greater than 5 rows

Is there any way to use MySQL to only return an average if there are more than X rows?

I am currently using the following query:

SELECT round(AVG(a_points),1) as a from points where user_id=X

Can this be done in MySQL or do I have to do a row count first then execute this statement?

The table contains

user_id     a_points     b_points

So a user could have lots of b_points but only 4 a_points and I wouldn't want to average at that point.

This question and answers originated from www.stackoverflow.com
Question by (8/1/2011 3:39:36 PM)

Answer

Will it work for you ?
SELECT round(AVG(points),1) as a from points where user_id=X HAVING COUNT(*) >5

Answer by

Find More Answers
Related Topics  mysql  average
Related Questions
  • Getting the average number of orders per day using mysql

    I have the following table structure: ID, User_ID, DateTime Which stores a user id and datetime of an order purchased. How would I get the average number of orders a day, across every row? …
  • Mysql Average on time column?

    SELECT avg( duration ) as average FROM `login`; The datatype for duration is "time", thus my value is like: 00:00:14, 00:20:23 etc I execute the query it gives me: 2725.78947368421 What is…
  • Moving average - MySQL

    I'm trying to implement system-wide login throttling and I need to calculate the daily average number of failed login attempts from the last 3 months. I'm currently inserting a record on every lo…
  • MySQL Daily Average over a month

    I'm pulling several status over a specific time period and I'd like to pull another stat that would be "average sales per day" over this time period. I'm not sure how to do daily averages over a spe…
  • Get the average of groups of n rows with MySQL

    I'm currently stuck trying to get the average value of groups of n rows using MySQL. I have a MySQL table (data_conso) composed of columns in the following format : id (int); date(datetime); data…
  • MySQL Union and Average

    I've no idea if I am using UNION correctly in this scenario - there may well be a better/easier way and I'm open to suggestions: I have the following code: SELECT COUNT(*), AVG (q1) AS q1, AVG…
  • MySQL: Is it possible to compute MAX( AVG (field) )?

    My current query reads: SELECT entry_id, user_id, cat_id, AVG( rating ) as avg_rate FROM `entry_rate` WHERE 1 GROUP BY entry_id cat_id relates to different categories: 1, 2, 3 or 4 Is ther…
  • MySQL sort by average of two averages

    I am working on a contest site where there are two types of users, normal site members, and judges. Each can use a drag and drop tool to order the entries in a particular contest in the order they c…
  • Select average from MySQL table with LIMIT

    I am trying to get the average of the lowest 5 priced items, grouped by the username attached to them. However, the below query gives the average price for each user (which of course is the price), …
  • 10 period moving average in MySql without using date

    I have a table of goalie data, snipet below year gameid player sv% gamenum 2009 200165 John Smith 0.923 0165 2009 209754 John Smith 1.000 9754 2009 206938 John Smith 1.000 6938 2009 206…