简体   繁体   English

按日期统计注册用户

[英]Count registered users by date

I need some help with this MySQL query. 我需要有关此MySQL查询的帮助。 I have the following fields in the DB 我在数据库中有以下字段

id     created_on            
1      2016-02-15 12:47:09     
2      2016-02-24 12:47:09    
3      2016-02-29 12:47:09    
4      2016-03-11 12:47:09    
5      2016-03-15 12:47:09    
6      2016-03-22 12:47:09    
7      2016-04-10 12:47:09    
8      2016-04-11 12:47:09    

I need to count the total records for the past 4 months. 我需要计算过去4个月的总记录。 i did this so far, 到目前为止,我做到了

SELECT YEAR(created_on) as year_val, MONTH(created_on) as month_val ,COUNT(*) as total
FROM `user`
GROUP BY YEAR(created_on), MONTH(created_on)

thanks 谢谢

add

WHERE created_on >= DATE_ADD(CURDATE(), INTERVAL - 4 MONTH) 在创建日期> = DATE_ADD(CURDATE(),间隔-4个月)的地方

it will return 它将返回

"year_val"   "month_val"   "total"
"2016"       "3"           "1"
"2016"       "4"           "2"
"2016"       "5"           "1"

SELECT count(id) FROM table WHERE created_on >= '2016-02-15 12:47:09' AND created_on <= '2016-06-15 12:47:09'; 从表中选择count(id)WHERE created_on> ='2016-02-15 12:47:09'AND created_on <='2016-06-15 12:47:09';

should work for your counter 应该为您的柜台工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM