高手你好,,  
我想写一条,sql 语句  查找30条  ("fs")=1 的记录 ,如果("fs")=1记录不足30条  那么有多少显示多少 ,剩下的用 ("fs")=2 显示 如果还不足,再显视,("fs")=3记录,,

解决方案 »

  1.   

    SELECT TOP 30 * FROM tb ORDER BY fs
    ...
      

  2.   

    只要查询的结果按你的规则排序,再取前30条记录即可
    select top 30 fs from 表 where fs>0 order by fs
      

  3.   

    高手你好,,   
    我想写一条,sql 语句  查找30条  ("fs")=1 的记录 ,如果("fs")=1记录不足30条  那么有多少显示多少 ,剩下的用 ("fs")=2 显示 如果还不足,再显视,("fs")=3记录,,--
    select top 30 * from
    (
    select top 30 * from tb where fs = 1
    union all
    select top 30 * from tb where fs = 2
    union all
    select top 30 * from tb where fs = 3
    ) t
      

  4.   

    select top 30 * from table where fs='1' or fs='2' or fs ='3' order by fs
      

  5.   

    SELECT TOP 30 * FROM tb where fs> 0 ORDER BY fs 
      

  6.   


    select top 30 * from
    (
    select top 30 *,'1' as px from tb where fs = 1
    union all
    select top 30 *,'1' as px from tb where fs = 2
    union all
    select top 30 *,'1' as px from tb where fs = 3
    ) t
    order by px 
      

  7.   

    SELECT * FROM 
    (SELECT *, ROW_NUMBER() OVER (PARTITION BY fs ORDER BY 任意一个字段) AS NUM FROM TB) T
    WHERE NUM>=30 ORDER BY FS,NUM
      

  8.   

    重金诚聘C++
    http://topic.csdn.net/u/20080227/14/8bce0844-bd15-42f0-9cda-a343d5d6601b.html?seed=2111206245