我有兴趣了解上个月每天有多少用户注册。我有这个非常简单的查询,告诉我上个月注册了多少用户。如何修改查询以便在白天给我结果?
SELECT first_name, last_name, created_at
FROM users
WHERE created_at > '2017-01-01'
AND created_at < '2017-02-01'
ORDER BY created_at DESC;
答案 0 :(得分:1)
SELECT count(*) as user_cnt, created_at
FROM users
WHERE created_at > '2017-01-01'
AND created_at < '2017-02-01'
GROUP BY created_at
如果created_at
字段是日期时间
SELECT count(*) as user_cnt, date(created_at) as created_date
FROM users
WHERE created_at > '2017-01-01'
AND created_at < '2017-02-01'
GROUP BY date(created_at)