我有两张表,类型如下:
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该怎么写?
where a.type=b.type_id and (a.Operation_date+b.Keep_days<getdate())
select a.type from a inner join b on a.type=b.typeid
where a.op_date+b.keep_days>GetDate()
where a.op_date+b.keep_days>GetDate()
或
select * from a inner join b on a.type=b.typeid
where dateadd(day,b.keep_days,a.op_date)>GetDate()