我有两张表,类型如下:
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该怎么写?

解决方案 »

  1.   

    select A.name,A.Type,A.Operation_Date,B.Type_ID,B.Type_Name,B.Keep_days
    from A,B
    where (select datediff(A.Operation_Date,getdate())>B.Keep_days
    //试试看行不行
      

  2.   

    select * From a,b where 
    a.Type_ID=b.Type_ID
    and 
    datediff(day,Operation_Date,getdate())>=保留日期
      

  3.   

    select * From a,b where 
    a.Type_ID=b.Type_ID
    and 
    datediff(day,Operation_Date,getdate())>=Keep_days
      

  4.   

    select A.operation_Date as F1,B.Keep_days from A,B as F2 Where A.Type=B.Type_ID
    取出来以后在程序中可以判断!
    比如:当前日期:IF date-F1>F2 为过期值
      

  5.   

    select A.name,A.Type,A.Operation_Date,B.Type_ID,B.Type_Name,B.Keep_days
    from A,B
    where (a.Type=b.Type_ID)and((select datediff(A.Operation_Date,getdate())>B.Keep_days)
      

  6.   

    select *
    from a,b
    where (a.type=b.type_id) and (datediff(day,operation_date,getdate())>=keep_days);
      

  7.   

    select a.*,b.Keep_days from a left join b on a.type=b.type_id where 
    datediff(day,operation_date,getdate())>=keep_days
      

  8.   

    select a.Name,a.Type 
    from a inner join b on a.type=b.type_id
    where dateadd(day,b.keep_days,a.operation_date)>getdate()
      

  9.   

    select *
    from a,b
    where (a.type=b.type_id) and (datediff(day,operation_date,getdate())>=keep_days);