select top 5 * from sp_info where (id not in (select top 5 id from sp_info where ischk=1 and  (sptype=4 or sptype=5) order by id desc)) and ischk=1 and  (sptype=4 or sptype=5) order by id desc

解决方案 »

  1.   


    select 
        top 5 * 
    from 
        sp_info 
    where 
        (id not in (select 
                        top 5 id    --替换此处
                    from 
                        sp_info 
                    where 
                        ischk=1 and  (sptype=4 or sptype=5) order by id desc)) 
        and 
        ischk=1 
        and 
        (sptype=4 or sptype=5) 
    order by 
        id desc
      

  2.   

    not in 或in后面要指定单个字段不能多个字段.
      

  3.   

    select top 5 * from sp_info where 
    id not in 
         (
            select top 5 id from sp_info where ischk = 1 and (sptype=4 or sptype=5) order by id desc
         )
    and ischk = 1 and (sptype=4 or sptype=5)
    order by id desc
      

  4.   

    select top 5 * from sp_info where 
    id not in (select top 5 id from sp_info where ischk=1 and (sptype=4 or sptype=5) order by id desc)
    and ischk=1 
    and (sptype=4 or sptype=5) order by id desc
      

  5.   

    select top 5 *
    from sp_info 
    where (id not in (select top 5 id 
      from sp_info 
      where ischk=1 and  (sptype=4 or sptype=5) 
      order by id desc))
     and ischk=1 and  (sptype=4 or sptype=5) 
    order by id desc