Select average from MySQL table with LIMIT

試著忘記壹切 提交于 2019-11-29 05:29:04
OMG Ponies

I think this is what you're after:

SELECT AVG(items.price)
  FROM (SELECT t.price
          FROM TABLE t
         WHERE t.price > '0' 
           AND t.item_id = '$id'
      ORDER BY t.price
         LIMIT 5) items

It will return the average of the 5 lowest prices - a single answer.

Aman Dhadwal

Simple solution below.

Query:

SELECT  AVG(Column_name) 
FROM  (SELECT Column_name 
FROM  Table
WHERE  ColumnID < number[Limit you want] )
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!