如何选择SQL Server数据库中的前6个月记录 [英] how to select top 6 month record in sql server database

查看:551
本文介绍了如何选择SQL Server数据库中的前6个月记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生

我想选择前6个月的记录.

八月,九月,八月....

请告诉我

在此先感谢

Dear sir

i want to select top 6 month record.

oct, sept,aug,....

plese tell me

thanks in advance

推荐答案

希望此查询解决您的问题
Hope this query solve your problem
select * from tablename where month(datecolumn)>'6'


select * from tablename where month(datcolumn) > 6 


如果正确,您想检索从今天开始的最近6个月的数据?实例,如果您今天(2011年10月31日)运行查询,则系统应能够检索2011年5月1日至2011年10月31日之间的数据

如果正确,示例中的datetime列为HireDate

If am right, you want to retrieve the data for the last 6 months from today ?, for instance if you run the query today (31 Oct 2011) the system should be able to retrive the data between 1st May 2011 to 31 Oct 2011

If am right and the datetime column in my example is HireDate

select *
from   employees
where CAST(floor( CAST( HireDate AS FLOAT ) )AS DATETIME) between CAST(floor( CAST( DATEADD("M",-6,GETDATE()) AS FLOAT ) )AS DATETIME) +1
and CAST(floor( CAST( GETDATE() AS FLOAT ) )AS DATETIME)


这篇关于如何选择SQL Server数据库中的前6个月记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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