您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql-MYsql 数据库 ,有个sql如何写

2024/3/10 21:39:50发布27次查看
mysqljava数据库
当前有张news表 有字段 addtime ,name ,
查询当前时间起,24小时前的数据,时间不知怎么写。
回复内容: 1查询今天的信息记录:1 select * from article where to_days(add_time) = to_days(now());2查询昨天的信息记录:2 select * from article where to_days(now()) – to_days(add_time) 3 查询近7天的信息记录:3 select * from article where date_sub(curdate(), interval 7 day) add_time);4 查询近30天的信息记录:4 select * from article where date_sub(curdate(), interval 30 day) add_time);5查询本月的信息记录:5 select * from article where date_format(add_time, ‘%y%m') = date_format(curdate() , ‘%y%m');6 查询上一月的信息记录:6 select * from article where period_diff(date_format(now() , ‘%y%m') , date_format(add_time, ‘%y%m')) =1; select * from news where datediff(year,addtime,getdate())
或者select * from news where addtime> sysdate-1
不需要考虑这个addtime的日期类型吗?
思路是把sysdate-addtime>1,当然,前提是日期格式相同
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product