I have a registration list for each SKU; then for each SKU I would like to be able to obtain the prices of the last 2 months Different (Months registered) (and that I can recognize between annual changes like December 2016 and January 2017) the problem that there is a jump between months.
the table has the following scheme
id sku precio fecha Actualizacion
1 10101 7.40 2016-12-23 11:58:05
2 10102 7.35 2016-12-23 11:58:06
3 10103 7.70 2016-12-23 11:58:07
4 10101 7.40 2017-02-15 11:58:05
5 10102 7.35 2017-02-15 11:58:06
6 10103 7.70 2017-02-15 11:58:07
7 10101 7.50 2017-05-06 11:58:11
8 10102 7.55 2017-05-06 11:58:12
9 10103 7.90 2017-05-06 11:58:05
I was trying to adapt this example:
SELECT id, thread_id, user_id, subject, body, date_sent
FROM messages WHERE date_sent IN (
SELECT MAX( date_sent )
FROM messages WHERE user_id =6 GROUP BY thread_id
)
ORDER BY thread_id ASC , date_sent DESC;
Update:
Manipulating something like this, but I have to prevent you from taking 2 records of the same month:
SELECT *
FROM tabla
WHERE
(YEAR('Date_Rel') <= NOW() + INTERVAL 1 YEAR)
AND
(MONTH('Date_Rel') <= NOW() + INTERVAL 1 MONTH)
ORDER
BY 'Date_Rel' DESC;