简体   繁体   中英

Adding AVG(Price) into a mySQL query?

I have the following query

$query = "SELECT * FROM used ".$conditionString." ORDER BY id DESC LIMIT $offset, $rec_limit";

But now I want to know also the average price of the returned rows

AVG(Price) AS PriceAverage

How to do this?

this should work for you:

$query = "SELECT *,AVG(Price) FROM used ".$conditionString." ORDER BY id DESC 
GROUP BY id WITH ROLLUP 
LIMIT $offset, $rec_limit";

demo: http://sqlfiddle.com/#!2/4938f/1/0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM