SELECT MAX(id) FROM `tbl`
WHERE createdat BETWEEN ADDDATE(DATE_FORMAT(NOW() ,"%Y-%m-%d"), INTERVAL -6 DAY) AND DATE_FORMAT(NOW(),'%Y-%m-%d')
GROUP BY DATE_FORMAT(createdat,'%Y-%m-%d')
)
前提你的表要有自增主键
select * from audit_session where login_time<=(CurDate()-7) and login_time>='DATE_SUB(now() , INTERVAL 1 DAY) 00:00:00'这可能需要自定义一个过程procedure了
delimiter $$drop procedure if exists wk
create procedure wk()
begin
declare i int
set i = 1
while i <= 7 do
select date_add(date_sub("2018-09-03",interval 7 day),interval i day)
set i = i + 1
end while
end $$
delimiter
call wk()
注意
date_add()是增加日期的函数
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)