create proc proc_t
as
select top 10 * into tmp from 表 where 置顶标记=1
if @@rowcount<10
exec('insert into tmp select top '+ltrim(10-@@rowcount)+' * from 表 where 置顶标记=0 order by 时间 desc')
select * from tmp
drop table tmp
as
select top 10 * into tmp from 表 where 置顶标记=1
if @@rowcount<10
exec('insert into tmp select top '+ltrim(10-@@rowcount)+' * from 表 where 置顶标记=0 order by 时间 desc')
select * from tmp
drop table tmp
select top 10 * from table order by 置顶 desc,时间
select top 10 * from table order by 置顶 desc,时间 desc
假设置顶标记=1为置顶标记 true,置顶标记=0为置顶标记 false
select top 10 * from
(
select * from table where 置顶标记= 1
union
select top 20 * from table where 置顶标记 = 0 order by 时间 desc
) as a