例如表t1
id name type
1 xxxx 1
2 xxxs 1
3 xxxq 2
select top 5 * from t1 where type = 1
比如要取type=1的5条记录,但是如果type=1的不足5条,比如只有2条,那就去掉type=1的条件再取3条,也就是总记录数总是5条
id name type
1 xxxx 1
2 xxxs 1
3 xxxq 2
select top 5 * from t1 where type = 1
比如要取type=1的5条记录,但是如果type=1的不足5条,比如只有2条,那就去掉type=1的条件再取3条,也就是总记录数总是5条
top 5 *
from
t1
order by
case when type = 1 then 0 else 1 end asc,type
--嗯:写的好,也许type有小于1的!考虑得周到!
from table
order by (case type when '1'then 1 else 0 end) desc