D
D
Dmitry2015-05-22 16:19:57
MySQL
Dmitry, 2015-05-22 16:19:57

How to make SQL selection of average values ​​of the last 5 (by date) rows?

You need something like:
SELECT id, vendor_id, AVG(items_count) as average_items
FROM `af_vendor_stock_files`
GROUP BY vendor_id
...but you need to take the last 5 (ORDER BY created_at DESC) for each vendor_id.
How?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Karetnikov, 2015-05-22
@art_karetnikov

read about limit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question