select * from tb order by case when isnull(col,'')='' then 0 else 1 end,col
order by isnull(col,'') 这样处理一下
select * from tb order by (CASE WHEN (ISNULL(col1, '') = '' OR ISNULL(col2, '') = '') THEN NULL ELSE '' END)
-- 两列同时为空,排在最前面,其中之一列为空其次,两列都不为空排在后面 select * from tb order by case when isnull(col1,'')='' and isnull(col2,'')='' then 0 when isnull(col1,'')='' or isnull(col2,'')='' then 1 else 2 end,col1,col2
from tb
order by case when isnull(col,'')='' then 0 else 1 end,col
这样处理一下
from tb
order by (CASE WHEN (ISNULL(col1, '') = '' OR ISNULL(col2, '') = '') THEN NULL ELSE '' END)
select *
from tb
order by case when isnull(col1,'')='' and isnull(col2,'')='' then 0
when isnull(col1,'')='' or isnull(col2,'')='' then 1 else 2 end,col1,col2