Table
id | usr | how | dt ----------------------------- 1 | 101 | 10 | 2016-10-16 ----------------------------- 2 | 101 | 20 | 2016-10-16 ----------------------------- 3 | 101 | 30 | 2016-10-17 You need to make such a request:
SELECT id,how, MONTH(dt) AS `dt` FROM stat WHERE usr = '101' GROUP BY YEAR(dt), MONTH(dt) But it gives out in the grouping the first lines, such as id 1, and in fact it is necessary id 3. ORDER BY id DESC does not help
I tried it, but also not
SELECT * from ( SELECT id,how, MONTH(dt) AS `dt` FROM stat WHERE usr = '101' ORDER BY id DESC) AS te GROUP BY YEAR(te.dt), MONTH(te.dt) ORDER BY te.id DESC