在表中最多有五条数据。
1
2
3
4
5
我想查找出少哪些数据。并且取出最小的一条

解决方案 »

  1.   

    例如你的字段名为 xid,表名为 x_eng 那么:select top 1 xid from x_eng ORDER BY xid ASC
      

  2.   


    --最小的一行
    select top 1 xid from x_eng ORDER BY xid ASC
    --最小的10行
    select top 10 xid from x_eng ORDER BY xid ASC
      

  3.   


    SELECT TOP 1 ID+1 
    FROM x_eng AS aaa 
    WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID)
    ORDER BY aaa.ID DESC
      

  4.   

    如果要全部显示:SELECT ID+1 
    FROM x_eng AS aaa 
    WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID)
    ORDER BY aaa.ID DESC
      

  5.   

    select min(c.b) from 
    (select 1 as b,count(*) as a  from 表名 where 字段=1 union all 
     select 2 as b,count(*) as a  from 表名 where 字段=2 union all 
     select 3 as b,count(*) as a  from 表名 where 字段=3 union all 
     select 4 as b,count(*) as a  from 表名 where 字段=4 union all 
     select 5 as b,count(*) as a  from 表名 where 字段=5    ) as c 
    where c.a=0
      

  6.   


    --测试环境
    CREATE TABLE x_eng(id int)INSERT x_eng([id]) select 1
    UNION ALL select 2
    UNION ALL select 5SELECT TOP 1 ID+1 
    FROM x_eng AS aaa 
    WHERE aaa.ID=(select count(*)+1 from x_eng where aaa.ID>ID)
    ORDER BY aaa.ID DESC--结果
    3
      

  7.   

    SQL Server中执行通过:create table tab(XH int)
    insert into tab values(2)
    insert into tab values(3)
    insert into tab values(5)select * from tabselect top 1 NewXH from 
    (select XH,(select count(*)+1 from tab as Y where Y.XH<X.XH) as NewXH
    from tab as X) as ABC 
    where XH <> NewXH
    order by XH drop table tab
      

  8.   


    select min(id+1) kk from tb where id+1 not in (select * from tb)
      

  9.   

    declare  @tb table(id int)
    insert  @tb 
    select 1 union all
    select 2 union all
    select 3 union all
    select 4 union all
    select 7 union all
    select 9
    select min(id+1) kk from @tb where id+1 not in (select * from @tb)/*结果kk          
    ----------- 
    5(所影响的行数为 1 行)
    */