发布网友 发布时间:2022-04-24 10:09
共4个回答
热心网友 时间:2022-04-08 10:15
select * from wap_content where week(created_at) = week(now)
如果要严格要求是某一年的,那可以这样
查询一天:
select * from table where to_days(column_time) = to_days(now());
select * from table where date(column_time) = curdate();
查询一周:
select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time);
查询一个月:
select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <=
date(column_time);
查询一年:
select * from table where DATE_SUB(CURDATE(), INTERVAL 1 YEAR) <= date(column_time);
扩展资料
mysql查询最近7天的数据:
1,(以当天为起点)
SELECT * FROM tb_equity e where DATE_SUB(CURDATE(), INTERVAL 6 DAY) <=
date(createdate)
2,(以数据库最新的时间最为最近的一天)
SELECT * FROM tb_equity e where createdate > DATE_ADD((select createdate from tb_equity
ORDER BY createdate DESC limit 1) ,INTERVAL -7 day)
and (select createdate from tb_equity ORDER BY createdate DESC limit 1) >= createdate
3,sql查询表中的重复数据
select * from 表名 where 字段名 in (select 字段名 from 表名 group by 字段名 HAVING COUNT(*)
> 1) order by 表名
参考资料来源:百度百科 - 结构化查询语言
参考资料来源:百度百科 - mySQL (关系型数据库管理系统)
参考资料来源:百度百科 - select (Linux 网络编程)
热心网友 时间:2022-04-08 11:33
查询一周的sql
week 函数是返回日期的星期数,最大是53周。可接收俩个参数date,mode。(date指定日期,mode 指定从星期几显示)
select * from wap_content where week(curdate())=week(created_at);显示的是当周的数据,从星期天开始。
从星期一开始显示:因为(周一、三、四、六)一年多三天所以你得加上一周开始计算
select * from wap_content where week(curdate())+1=week(created_at,1);希望对你有帮助。
热心网友 时间:2022-04-08 13:08
select * from wap_content where week(created_at) = week(now)
如果你要严格要求是某一年的,那可以这样
查询一天:
select * from table where to_days(column_time) = to_days(now());
select * from table where date(column_time) = curdate();
查询一周:
select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time);
查询一个月:
select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(column_time);
热心网友 时间:2022-04-08 14:59
MYSQL查询一周内的数据(最近7天的)语句为:
select * from wap_content where week(created_at) = week(now)
如果你要严格要求是某一年的,那可以这样
查询一天:
select * from table where to_days(column_time) = to_days(now());
select * from table where date(column_time) = curdate();
查询一周:
select * from table where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(column_time);
查询一个月:
select * from table where DATE_SUB(CURDATE(), INTERVAL INTERVAL 1 MONTH) <= date(column_time);
扩展资料
MySQL中查询语句的用法
一、查询所有数据
select * from Info 查所有数据
select Code,Name from Info 查特定列
二、根据条件查
select * from Info where Code='p001' 一个条件查询
select * from Info where Code='p001' and Nation='n001' 多条件 并关系 查询
select * from Info where Name='胡军' or Nation='n001' 多条件 或关系 查询
select * from Car where Price>=50 and Price<=60 范围查询
select * from Car where Price between 50 and 60 范围查询
三、模糊查询
select * from Car where Name like '%型' %通配符代表任意多个字符
select * from Car where Name like '%奥迪%' _通配符代表任意一个字符
select * from Car where Name like '_马%'
四、分组查询
select Brand from Car group by Brand having count(*)>2 查询所有系列中数量大于2的
五、分页查询
select * from Car limit 0,5 跳过几条数据取几条数据
六、去重查询
select distinct Brand from Car
参考资料来源:百度百科-数据库语言