-- 查詢每天的資料
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) as total,week(create_time) as time from op_endor_info group by week(create_time);
-- 查詢每月的資料
select count(1) as total,month(create_time) as time from op_endor_info group by month(create_time);
-- 查詢每年的資料
select count(1) as total,year(create_time) as time from op_endor_info group by year(create_time);
-- 其他:
-- date_add(,interval expr unit)
-- date_add(create_time,interval 1 day) 得到指定日期後一天的日期/把1改為任意數字就可以得到後n天的日期
-- date_sub(,interval expr unit)
-- date_sub(create_time,interval 1 day) 得到指定日期前一天的日期/把1改為任意數字就可以得到前n天的日期
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...
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...
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...