select createdate from cp_projectplan where   not exists ( select createdate from cp_projectplan where createdate < to_date('2010-09-02','yyyy-mm-dd') 
or createdate > to_date('2010-09-04','yyyy-mm-dd') )明明有9月3号创建的数据,为什么结果是空的

解决方案 »

  1.   

    --改成这样,你那样肯定是没有数据咯。那样在4号之后,在2号之前的日期啊
    select createdate from cp_projectplan where createdate between to_date('2010-09-02','yyyy-mm-dd') 
    and createdate > to_date('2010-09-04','yyyy-mm-dd')
      

  2.   

    --该打啊,我又不仔细了
    select createdate from cp_projectplan where createdate between to_date('2010-09-02','yyyy-mm-dd') 
    and to_date('2010-09-04','yyyy-mm-dd')
      

  3.   

    为什么写的那么复杂,等价于select createdate from cp_projectplan
    where  createdate between to_date('2010-09-02','yyyy-mm-dd') and createdate > to_date('2010-09-04','yyyy-mm-dd') )
    把你的数据贴些出来看看
      

  4.   

    select createdate from cp_projectplan where createdate between to_date('2010-09-02','yyyy-mm-dd') 
    and createdate > to_date('2010-09-04','yyyy-mm-dd')
      

  5.   


    我如果一定要用not exists  加 子查询  应该怎么写 我问这题 主要是为了搞明白not exists的用法
      

  6.   


    我如果一定要用not exists  加 子查询  应该怎么写 我问这题 主要是为了搞明白not exists的用法
      

  7.   

    --给你个例子吧
    --查询各部门中工资最的人
    select * from emp t
    where not exists(
      select 1 from emp where deptno=t.deptno
      and sal>t.sal)
      

  8.   


    select createdate from cp_projectplan a
    where  not exists (
    select createdate from cp_projectplan b where a.createdate=b.createdate
    and (b.createdate < to_date('2010-09-02 23:59:59','yyyy-mm-dd hh24:mi:ss') or b.createdate > to_date('2010-09-04','yyyy-mm-dd'))
    )--为什么不直接下面的,搞这么复杂
    select createdate from cp_projectplan where to_char(createdate,'yyyy-mm-dd')='2010-09-03'
      

  9.   

    你写的语句外层查询结果对内层的Exist子句没有限制,外层和内层查询相互独立了。相当于exists子句恒为true或恒为false.
    试下下面这句:
    select createdate from cp_projectplan t where   not exists 
    ( select createdate from cp_projectplan 
          where t.createdate <= to_date('2010-09-02','yyyy-mm-dd') 
            or t.createdate >= to_date('2010-09-04','yyyy-mm-dd') )
      

  10.   

    这个简单的例子仔细体会下就理解exists的用法了
      

  11.   

    我想应该是createdate字段存储的问题.如果createdate字段是date类型的,那么创建的时候肯定是会带时间的.如果筛选日期的时候不想考虑时间,则可以使用trunc()函数截断date类型的时间.这个查询没必要用子查询吧?
    select createdate from cp_projectplan t where trunc(t.createdate)='3-sep-2010';
    这个肯定能出来结果,LZ自己后面改成子查询吧.
      

  12.   

    select createdate from cp_projectplan where createdate between to_date('2010-09-02','yyyy-mm-dd')  
    and to_date('2010-09-04','yyyy-mm-dd')