我有一个用户列表,他们在注册时为每个用户分配了一个注册时间戳。
如何计算每个月为我的整个用户列表注册的用户数量,这个用户列表的时间跨度为23个月。
因此输出应该只有2列,一列是月份+年份,另一列是当月注册的用户数量。
有人可以提出查询吗?
示例数据
INSERT INTO `users` (`id`, `regdate`) VALUES
(861490, 1314021552),
(944392, 1317760487),
(674263, 1311119415),
(287512, 1305242049),
(125134, 1299310950),
(714619, 1311658393),
(777858, 1312508020),
(812091, 1312918459),
(979515, 1319524143),
(1009713, 1321038952),
(395950, 1307314421),
(552213, 1309435427),
(549979, 1309395329),
(919872, 1316468483),
(385920, 1307196494),
(825096, 1313085971),
(967657, 1318961937),
(136631, 1299825660),
(838405, 1313315222),
(984647, 1319803409),
(239280, 1303860435),
(917747, 1316368790),
(621945, 1310480971),
(1078781, 1324529892),
(897934, 1315556339),
(311070, 1305899412),
(830274, 1313157183),
(518156, 1308952471),
(524182, 1309037939),
(524142, 1309037521);
答案 0 :(得分:3)
SELECT DATE_FORMAT(FROM_UNIXTIME(regdate), '%Y-%m') AS month,
COUNT(*) AS registrations
FROM users
GROUP BY month