I have this table storing when a user last connected to a server:
+----+----------------------------+-----------+
| id | last_connection | something |
+----+----------------------------+-----------+
| 1 | 2017-03-23 10:39:14.000000 | bleh |
| 2 | 2014-03-20 07:05:51.000000 | blah |
| 3 | ... | ... |
+----+----------------------------+-----------+
I can select and count id that have been active in the last 2 months with something like: SELECT count(*) as '2months' FROM
statsWHERE TIMESTAMPDIFF(DAY, SUBSTRING_INDEX(
last_connection, ' ', 1), CURDATE()) < 60
, or in the last 3 months with SELECT count(*) as '3months' ... < 90
and so on, which gets me something like this:
+---------+
| 2months |
+---------+
| 1337 |
+---------+
My question is: is there a way to do group several TIMESTAMPDIFF in one unique query, and get something like the following?
+-----------+-------+
| last conn | count |
+-----------+-------+
| 1month | 1337 |
| 2month | 31337 |
| 3month | ... |
| ... | ... |
+-----------+-------+