sql获取这个月与上个月的数据(加分)
发布网友
发布时间:2022-04-07 15:24
我来回答
共4个回答
热心网友
时间:2022-04-07 16:53
1> SELECT GETDATE() AS 今天, DATEADD(mm, -1, GETDATE() ) AS 上月
2> go
今天 上月
----------------------- -----------------------
2011-10-13 17:01:23.223 2011-09-13 17:01:23.223
(1 行受影响)
上面是 sql server 的函数。
热心网友
时间:2022-04-07 18:11
select * from table where datepart(dd,时间)<=13
热心网友
时间:2022-04-07 19:46
select * from 表 where datepart(dd,时间)=13
热心网友
时间:2022-04-07 21:37
-------------------------------------------------------------------------------------------------------------------------- 上月1号-13号,这月1-13号--------------------
MSSQL: select * from [table] where [column] between dateadd(day,-day(getdate())+1,getdate()) and getdate() union all
select * from [table] where [column] between dateadd(day,-day(dateadd(month,-1,getdate()))+1,dateadd(month,-1,getdate())) and dateadd(month,-1,getdate())
oracle : select * from [table] where [column] between trunc(sysdate,'mm') and sysdate union all select * from [table] where [column] between trunc(add_months(sysdate,-1) ,'mm') and add_months(sysdate,-1)