表table 中有自增长列ID,INT类型,是否操作列Top,Bit类型 现在要查询在表Table中按ID排倒序,并且Top=1的数据排在面前我写的
select ID,Top from table where[Top]=1
union
select ID,Top from table order by ID desc这样虽然前面的数据是TOp=1的 但是后面的就不是倒序了 要怎么写?
select ID,Top from table where[Top]=1
union
select ID,Top from table order by ID desc这样虽然前面的数据是TOp=1的 但是后面的就不是倒序了 要怎么写?
order by case when top=1 then 0 else 1 end,ID desc
是对union后的全部结果进行排序
order by Top desc,ID desc
from table
order by case when top = 1 then 0 else 1 end,id desc