首页 新闻 会员 周边

.net查询近一个月订单和一个月前订单

0
悬赏园豆:20 [待解决问题]

.net查询近一个月订单和一个月前订单,这个功能sql语句怎样写呢,望各位高手告知下

沈大荣的主页 沈大荣 | 初学一级 | 园豆:2
提问于:2012-02-28 10:22
< >
分享
所有回答(7)
0

这两个要求都是一个SQL语句select * from table where timestr between @starttime and @endtime;

关键就是在@starttime , @endtime这两个参数值怎么来,近一个月比较简单啦,直接startime=system.DateTime.Now.AddDays(-30),endtime=system.DateTime.Now.上个月先得到本月再addmonth(-1)就行了

happydaily | 园豆:253 (菜鸟二级) | 2012-02-28 11:03
0
SELECT dataiff(day,StartTime,EndTime) FROM dbo.Date 
主要就是sql的查询
colyn | 园豆:79 (初学一级) | 2012-02-28 11:06
0
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())
小材小用 | 园豆:639 (小虾三级) | 2012-02-28 11:27
0
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月的分别归总

| 园豆:264 (菜鸟二级) | 2012-02-28 13:42
0
dreamhappy | 园豆:4 (初学一级) | 2012-02-28 14:09
0
  select * from orders where DATEDIFF(DAY,startime,endtime)<=30

近一个月的

  select * from orders where DATEDIFF(DAY,startime,endtime)between 30  and 60

这个应该就是一个月前的了。。。

Rookier | 园豆:652 (小虾三级) | 2012-02-28 17:30
0

表结构不清楚,写了也不一定是你想要的

小小刀 | 园豆:1991 (小虾三级) | 2012-02-28 22:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册