MYSQL統計每天 每週 每月 每年資料

2021-10-05 02:02:20 字數 737 閱讀 4726

查詢每天的資料

select count(1) as total, date_format(created_time,'%y-%m-%d') as days from task_execution group by days desc;

查詢每週的資料

select count(1) as total, week(created_time) as weeks from task_execution group by weeks desc;

查詢每月的資料

select count(1) as total, month(created_time) as months from task_execution group by months desc;

查詢每年的資料

select count(1) as total, year(created_time) as years from task_execution group by years desc;

注意:date_add(createtime,interval 1 day) 得到指定日期後一天的日期/把1改為任意數字就可以得到後n天的日期

date_sub(createtime,interval 1 day) 得到指定日期前一天的日期/把1改為任意數字就可以得到前n天的日期

MYSQL統計每天 每週 每月 每年資料

select count 1 as total,date format created time,y m d as days from task execution group by days desc select count 1 as total,week created time as wee...

Mysql查詢每天 每週 每月 每年的資料

查詢每天的資料 select count 1 as total,date format create time,y m d as time from op endor info group by date format create time,y m d 查詢每週的資料 select count 1...

mysql查詢每天每週每月每年的資料方法

查詢每天的資料 select count 1 as countnumber,date format createtime,y m d as datetime from testtable group by date format createtime,y m d 查詢每週的資料 select cou...