高手你好,,
我想写一条,sql 语句 查找30条 ("fs")=1 的记录 ,如果("fs")=1记录不足30条 那么有多少显示多少 ,剩下的用 ("fs")=2 显示 如果还不足,再显视,("fs")=3记录,,
我想写一条,sql 语句 查找30条 ("fs")=1 的记录 ,如果("fs")=1记录不足30条 那么有多少显示多少 ,剩下的用 ("fs")=2 显示 如果还不足,再显视,("fs")=3记录,,
...
select top 30 fs from 表 where fs>0 order by fs
我想写一条,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
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
(SELECT *, ROW_NUMBER() OVER (PARTITION BY fs ORDER BY 任意一个字段) AS NUM FROM TB) T
WHERE NUM>=30 ORDER BY FS,NUM
http://topic.csdn.net/u/20080227/14/8bce0844-bd15-42f0-9cda-a343d5d6601b.html?seed=2111206245