我有一个表格名称(任务),在这里我想要计数,比如先发生了多少次注册,然后在第二次发生了多少次注册怎么办?这个,我是mysql和PHP的新版本。
id name t_created_on
1 Kani 2017-03-03 12:45:18
2 yuvi 2017-03-04 12:45:18
3 Mahesh 2017-03-11 12:45:18
我在这里使用这种格式日期(“Y-m-d h:i:s”)
基于我的数据库第一周2注册,第二周是1。
预期结果:
第一周计数:2
第二周数:1
答案 0 :(得分:0)
SELECT WEEK(t_created_on) as week, count(*) as count
FROM my_table
GROUP BY WEEK(t_created_on)
ORDER BY WEEK(t_created_on);
答案 1 :(得分:0)
1
SELECT count(*) as records FROM tbl
WHERE t_created_on >= curdate() - INTERVAL DAYOFWEEK(curdate())+6 DAY
AND t_created_on < curdate() - INTERVAL DAYOFWEEK(curdate())-1 DAY
2
SELECT count(*) as weekrecord FROM tb1
WHERE
WEEK (date) = WEEK( current_date ) -1 AND YEAR( date) = YEAR( current_date );
注意:WEEK(current_date)-1:数字表示星期数。
答案 2 :(得分:0)
SELECT count(*) as weekrecord, MONTH(current_date) as monthwise
FROM tb1
WHERE
WEEK (date) = WEEK( current_date ) -1
AND YEAR( date) = YEAR( current_date );