如何计算记录数 [英] How to count Number of Records
问题描述
HI,
我有桌子学生
st_id,st_name,act_date
1 james 2/2/2012
2艾伯特2/4/2012
3约翰逊2012年1月30日
4希特勒2/2/2012
您可以看到act_date的第一条记录是2012年2月2日.
每条记录增加一个月.
例如:
今天的日期是2012年2月23日,请参阅第一个记录2012年2月2日.
2012年2月2日+添加一个月=> 2012年3月3日.
当我登录自己的网站(2012年2月23日)时,它必须显示计数为零.
当我登录自己的网站(2012年3月3日)时,它必须显示count = 2,即第一条记录和第四条记录.
相同的过程wlll必须跟随其他记录.
如何编写查询以根据该条件对记录进行计数,一个月后将其添加到记录中.
谢谢,
选择 RecordCount = count(st_id) 来自的学生 其中 datediff(day,dateadd(Month, 1 ,act_date),getdate())= 0
请让我知道上面的查询是否与您想要的不匹配.
您好,请在下面的查询中使用
选择 RecordCount = count(st_id) 来自的学生 其中 dateadd(Month, 1 ,act_date)< = getdate()
HI,
I have table student
st_id , st_name, act_date
1 james 2/2/2012
2 albert 2/4/2012
3 johnson 30/1/2012
4 hitler 2/2/2012
you can see the first record the act_date is 2nd Feb 2012.
Addign one month to Every record.
Ex:
Today date is 23rd Feb 2012, see the first record 2nd Feb 2012.
2nd Feb 2012+adding One Month=> 3rd March 2012.
When i logined into my web site (23rd Feb 2012) , it has to show the count Zero.
When i logined into my web site (3rd March 2012), it has to show the count=2 i.e the 1st record and 4th record.
Same process wlll have to follw to other records.
How to write a Query to count that records based on that condition adding after one month to the record.
Thanks,
Select RecordCount=count(st_id) from student where datediff(day,dateadd(Month,1,act_date),getdate())=0
Please let me know if the above query doesn''t match what you want.
Hi, use below query
Select RecordCount=count(st_id) from student where dateadd(Month,1,act_date) <= getdate()
这篇关于如何计算记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!