select * from 表名 where 条件 and count(其中一个字段名)<6

解决方案 »

  1.   

    select top 5 * from 表
      

  2.   

    set rowcount 5
    select * from table
      

  3.   

    回复人: wyqwn(飞扬) ( ) 信誉:100  2004-04-01 11:44:00  得分:0 
     
     
      select * from 表名 where 条件 and count(其中一个字段名)<6
     
     
    -----------
    出错了
      

  4.   

    一个分页显示数据的例子
    CREATE PROCEDURE sp_SearchResults 
      @SessionID int,
      @PageSize int,
      @CurrentPage int,
      @RecordCount int Output,
      @PageCount int Output
    ASdeclare @BeginRow int
    declare @EndRow int
    declare @BeginID int
    declare @EndID int--取出某SessionID的当前查询结果,使用临时表#temp的作用主要是缩小查询范围
    select * into #temp from 人事_员工基本信息表 where 员工ID = @SessionIDset @RecordCount = (select count(*) from #temp)set @PageCount = Round((@RecordCount / @PageSize), 0) + 1--如果@PageSize刚刚能整除@RecordCount,则@PageCount减1
    if @RecordCount = ((@PageCount - 1) * @PageSize)
      set @PageCount = @PageCount - 1--如果当前页的数值大于总页数,则把当前页重设为总页数的值
    if (@CurrentPage > @PageCount)
      set @CurrentPage = @PageCount--当结果集不为空时,查询返回当前页的结果集
    if @RecordCount > 0
    begin
      --取的当前页的开始位置和结束位置
      set nocount on
      set @BeginRow = @PageSize * (@CurrentPage - 1) + 1
      set rowcount @BeginRow
      select @BeginID = 员工id from #temp order by 员工id
      set @EndRow = @PageSize * @CurrentPage
      if @EndRow >= @RecordCount
        set @EndRow = @RecordCount
      set rowcount @EndRow
      select @EndID = 员工id from #temp order by 员工id
      set rowcount 0
      set nocount off
      --取位置结束  --根据开始位置和结束位置返回当前页的记录
      select * 
      from #temp 
      where 员工id between @BeginID and @EndID
      order by 员工id
    end
    else
      select * from #tempdrop table #temp
    GO
      

  5.   

    这是程序设计控制的,没有必要在SQL语句里这样做呢??