有一个表a,列1:c1,列2:c2,里面有3条记录。(c1:qq1,c2:tt1)、(c1:qq2,c2:tt2)、(c1:qq3,c2:tt3);想实现这样的结果:查询出qq2是否在这个表中,另外把表中排除qq2以后的记录查询出来,要求一条sql语句查询出来。

解决方案 »

  1.   

    SELECT * FROM TABLE WHERE C1=QQ2;
    SELECT * FROM TABLE WHERE C1 !=QQ2;
      

  2.   

    <a href='http://www.baidu.com'>点击到百度</a>
      

  3.   

    不知道你要的是不是这个,直接把代码copy运行就ok啦with 
    test
    as 
    (
     select 'qq1' as c1 , 'tt1' as c2 from dual 
     union
     select 'qq2' as c1, 'tt2' as c2 from dual 
     union
     select 'qq3' as c1, 'tt3' as c2 from dual 
     )
    select * from test where
    (
     select 
      case when 1=1 then 
      (select count(c1) from test where exists (select * from test where c1='qq2'))
     end from dual 
    ) > 0 and c1 != 'qq2'
      

  4.   

    select c1, c2
      from (select row_number() over(order by c1) as rn, c1, c2 from test)
     where rn >
           (select rn
              from (select row_number() over(order by c1) as rn, c1 from test)
             where c1 = 'qq2')
      

  5.   

    select * from blt_user d where (select count(*) from blt_user t where t.user_name ='admin')>0 and d.user_name<>'admin'