如何从sql server 2005中选择从今天到最近5天的数据. [英] How to select data from todays to last 5 days from the sql server 2005 >

查看:105
本文介绍了如何从sql server 2005中选择从今天到最近5天的数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从sql server 2005中选择从今天到最近5天的数据.
例如:
tblPaymentDetail(表名称)

字段为:
appPaymentDate
appAmount


在我的表中这样插入记录:

appPaymentDate appAmount

18-07-2012 100
2012年7月16日200
18-07-2012 300
2012年15月7日740


我想要最近5天的记录以及appAmount的总和.

结果:
假设今天是2012年7月20日

我要
19-07-2012 0
18-07-2012 400
17-07-2012 0
2012年7月16日200
15-07-2012 740

请帮帮我.

预先谢谢您.

How to select data from today to last 5 days from the sql server 2005.
example:
tblPaymentDetail(Table Name)

Fields Are:
appPaymentDate
appAmount


In my table records are inserted like this:

appPaymentDate appAmount

18-07-2012 100
16-07-2012 200
18-07-2012 300
15-07-2012 740


I want last 5 days record with sum of appAmount .

Result:
Assume todays date is 20-07-2012

I want
19-07-2012 0
18-07-2012 400
17-07-2012 0
16-07-2012 200
15-07-2012 740

please help me.

Thank you in advance.

推荐答案

尝试:
SELECT * FROM tblPaymentDetail WHERE appPaymentDate >= DATEADD(day, -5, GetDate())


select * from table where   day(appPaymentDate )   between   (day(getdate())-5)   and   (day(getdate()))


这篇关于如何从sql server 2005中选择从今天到最近5天的数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆