我有两张表,类型如下:
A:
字段 类型
Name String (名称)
Type int (类型)
Operation_Date Datetime (进入日期)B:
字段 类型
Type_ID int (类型)
Type_Name String (类型名称)
Keep_days int (保留天数)A表中的“Type”和B表中的“Type_ID”相关联,
现我想根据这两张表统一找出A表中的“进入日期”加上其相应的B表中的“保留天数”后,已过期的所有数据(即:早于今天的),请问SQL该怎么写?
A:
字段 类型
Name String (名称)
Type int (类型)
Operation_Date Datetime (进入日期)B:
字段 类型
Type_ID int (类型)
Type_Name String (类型名称)
Keep_days int (保留天数)A表中的“Type”和B表中的“Type_ID”相关联,
现我想根据这两张表统一找出A表中的“进入日期”加上其相应的B表中的“保留天数”后,已过期的所有数据(即:早于今天的),请问SQL该怎么写?
from A,B
where (select datediff(A.Operation_Date,getdate())>B.Keep_days
//试试看行不行
a.Type_ID=b.Type_ID
and
datediff(day,Operation_Date,getdate())>=保留日期
a.Type_ID=b.Type_ID
and
datediff(day,Operation_Date,getdate())>=Keep_days
取出来以后在程序中可以判断!
比如:当前日期:IF date-F1>F2 为过期值
from A,B
where (a.Type=b.Type_ID)and((select datediff(A.Operation_Date,getdate())>B.Keep_days)
from a,b
where (a.type=b.type_id) and (datediff(day,operation_date,getdate())>=keep_days);
datediff(day,operation_date,getdate())>=keep_days
from a inner join b on a.type=b.type_id
where dateadd(day,b.keep_days,a.operation_date)>getdate()
from a,b
where (a.type=b.type_id) and (datediff(day,operation_date,getdate())>=keep_days);