日期:2014-05-17  浏览次数:20474 次

如何找出距当前时间大于XX天的记录?
SQL2000下,假设有这么两张表 
表1
"用户编号" (主键)
"用户姓名"
.
.
.
表2:
"用户标号"
"时间"
如何通过SQL语句查询出距当前时间超过XX天的用户的详细信息?下面是我写的一点点,感觉没思路了!
SQL code
DECLARE @date datetime
DECLARE @diff_date datetime
DECLARE @current_date datetime
set @current_date = '2012-12-10'
set @date = 
( 
SELECT top 1 时间 
FROM BuyInformation 
ORDER BY 时间 DESC
)
set @diff_date = @current_date - @date


------解决方案--------------------
SQL code
SELECT * FROM USERINFO WHERE userid IN  (SELECT userid FROM BuyInformation WHERE  DATEDIFF(day, 时间, GETDATE()) > 30)