这两个要求都是一个SQL语句select * from table where timestr between @starttime and @endtime;
关键就是在@starttime , @endtime这两个参数值怎么来,近一个月比较简单啦,直接startime=system.DateTime.Now.AddDays(-30),endtime=system.DateTime.Now.上个月先得到本月再addmonth(-1)就行了
SELECT dataiff(day,StartTime,EndTime) FROM dbo.Date
主要就是sql的查询
use tempdb
if object_id('tab_order') is not null drop table tab_order
Go
create table tab_order(
orderid int,
orderdate datetime,
)
Go
insert into tab_order
select 1,'2012-01-01'
union all
select 2,'2012-01-20'
union all
select 3,'2012-02-2'
union all
select 4,'2012-02-20'
--近一个月订单
select * from tab_order where orderdate<=dateadd(dd,-30,getdate())
--一个月前订单
select * from tab_order where orderdate>=dateadd(dd,-30,getdate())
select case when date_month < 11 then '11以前' else convert(varchar,date_month) end date_month ,sum(number) number
from table1
group by case when date_month < 11 then '11以前' else convert(varchar,date_month) end
order by case (case when date_month < 11 then '11以前' else convert(varchar,date_month) end )when '11以前' then 1 else 0 end
上面是参考sql语句,我是将11月份以前的数据归总到一起,11月和12月的分别归总
select * from orders where DATEDIFF(DAY,startime,endtime)<=30
近一个月的
select * from orders where DATEDIFF(DAY,startime,endtime)between 30 and 60
这个应该就是一个月前的了。。。
表结构不清楚,写了也不一定是你想要的