mysql中怎么查询一周内,三个月内,半年内的数据?

mysql中怎么查询一周内,三个月内,半年内的数据?,第1张

mysql中怎么查询一周内,三个月内\x0d\x0a使用sql语句查询日期在一周内的数据\x0d\x0aselect * from ShopOrder where datediff(week,ordTime,getdate()-1)=0 //查询当天日期在一周年的数据\x0d\x0aselect * from ShopOrder where datediff(day,ordTime,getdate()-1)=0 //查询当天的所有数据\x0d\x0a SELECT * FROM A where datediff(d,datetime,getdate()) 回答于 2022-12-11

-- 算法:日期 >= ( 今天 - 3个月 )

WHERE sendtime >= DATE_SUB( CURRENT_DATE() , INTERVAL 3 MONTH )

1、创建测试表,create table test_date2(id number, v_date date)

2、插入测试数据,

insert into test_date2

select level, sysdate - level * 2 from dual connect by level <100

3、查看表中所有记录,select t.* , rowid from test_date2 t

4、编写sql代码,取近三个月数据,用add_months函数

select t.*, rowid from test_date2 t where v_date >add_months(sysdate, -3)

5、编写sql代码,取近10天数据,用sysdate-10函数,

select t.*, rowid from test_date2 t

where v_date >sysdate-10 order by v_date


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/7239904.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-03
下一篇 2023-04-03

发表评论

登录后才能评论

评论列表(0条)

保存