表名ship,字段,edit,group,date1,date2,date3
查询要求:只有当edit='1',edit='2'的时候,才能进行下面的查询
group='small' or group='big',date1是一个区间时间比如2010年10月1号到2010年10月31号,
date2-date3要大于4select * from ship where edit='1' or edit='2' or group='small' or group='big' and date1>'2010/10/1' and date1<'2010/10/31' and ((date2-date3)>4)  请问该怎么修改才能达到我要的目的 

解决方案 »

  1.   


    select * from ship where (edit='1' or edit='2') and (group='small' or group='big') and date1>'2010/10/1' and date1<'2010/10/31' and (datediff(dd,date3,date2)>4) 
    不知道 这样能满足LZ要求不
      

  2.   

    最好给出完整的表结构,测试数据,计算方法和正确结果.否则耽搁的是你宝贵的时间。
    如果有多表,表之间如何关联?
    发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
      

  3.   

    测试数据
    edit     group        date1         date2                  date3
    1        small        2009/11/12    2009/12/3             2009/12/1
    2        big          2010/1/3      2010/1/20             2010/1/19
    1        small        2010/2/1      2010/2/7              2010/2/1
    6        china        2010/11/12    2010/11/20            2010/11/14
    只有当EDIT=1或者2的时候,group等于small或者big的时候,date1在2010/9/30,2010/12/30之间,date2-date3>4的时候
    测试结果
    1        small        2010/10/1     2010/11/1             2010/10/20
      

  4.   

    select * from #tb
    where edit not in (1,2) 
    or
    ( edit  in (1,2) 
     and [group] in('small','big')
    and date1 between '2010/9/30' and '2010/12/30'
    and datediff(day,date3,date2)>4 )edit group date1      date2      date3
    ---- ----- ---------- ---------- ----------
    6    china 2010/11/12 2010/11/20 2010/11/14(1 行受影响)按你的要求是这样但是结果和你的不一样