Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
価格が最も低い 5 つの商品の平均を取得しようとしています。商品に付けられたユーザー名でグループ化されています。ただし、以下のクエリは各ユーザーの平均価格 (もちろん価格です) を示していますが、1 つの回答だけを返したいと考えています。
SELECT AVG(price) FROM table WHERE price > '0' && item_id = '$id' GROUP BY username ORDER BY price ASC LIMIT 5
これがあなたが求めているものだと思います:
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
5 つの最低価格の平均 - 単一の回答が返されます。