正在做一个小项目,有一表sys_pc,包含字段lastdate(最近开机时间),room(所在机房),还有其它基本信息,不列举。字段类型都为文本。
先要实现如下功能:从数据库中查询出 lastdate小于startdate或者lastdate大于enddate 并且room=1的记录,前两个是或的关系,然后和最后一个机房条件 与,求sql语句!

解决方案 »

  1.   

    oracle 数据库:select t.lastdate,t.room from sys_pc t where t.lastdate < startdate
    or t.lastdate > enddate and t.room=1
      

  2.   

    select * from sys_pc where lastdate <= startdate or lastdate >=enddate and room=1
      

  3.   

    一楼,用的是access
    二楼,就是三个条件,前两个是或得关系,然后和第三个与.
      

  4.   

    使用union呢?
    select * from sys_pc where lastdate<startdate and room=1  UNION
    select * from sys_pc where lastdate>enddate and room=1  
      

  5.   

    你自己不是很清楚地表述出来了,sql语句也不难了吧
      

  6.   

    前两个是或的关系,然后和最后一个机房条件与
    select * from sys_pc where (lastdate <= startdate or lastdate >=enddate) and room=1
      

  7.   

    lastdate小于startdate或者lastdate大于enddate 这个没反了吗,一般查的都是startdate<=lastdate<=enddate(在时间段内)lastdate一般来说应该是datetime日期时间(如:2010-04-07 16:45:00),startdate、enddate是日期(如:2010-04-01)lastdate用文本类型很怪select * from sys_pc where startdate <= lastdate and lastdate<(enddate+1天) and room=1
      

  8.   

    试这个:
    (假设lastdate是“月/日/年”的格式储存的,如果不是这样,就需要先转换成这样的格式)
    String startDate = "01/01/2010"; //in month/day/year format
    String endDate = "04/01/2010"; //in month/day/year format
    String roomNo = "1";//lastdate must in month/day/year format
    String sql = ”Select * from sys_pc "
               + "where ((CDate(lastdate) < ” + "#" + startDate + "# )"
               + "       or (CDate(lastdate) > ” + "#" + endDate + "# ))"
               + "       and room = '" + roomNo + "'"
      

  9.   

    select t.lastdate,t.room from sys_pc t where t.lastdate < startdate
    or t.lastdate > enddate and t.room=1