27,579
社区成员
发帖
与我相关
我的任务
分享
SELECT * FROM [Table] ORDER BY LEN(NAME),3
select *
from news
order by len(name),case when type='国际' then 0 else 1 end
create table enshizhouyu( Id int , Name varchar(20), Type varchar(20))
insert into enshizhouyu
select 1 , 'a ' , '国际' union all
select 2 , 'ae' , '国内' union all
select 3 , 'abc' , '国内' union all
select 4 , 'aec' , '国际'
select Id,Name,Type from (
select *,(case [Type] when '国际' then 0 else 1 end) as ascid
from enshizhouyu )A
order by len(Name),A.ascid
=============
/*--Id Name Type
----------- ---------- ----------
1 a 国际
2 ae 国内
4 aec 国际
3 abc 国内
select *
from news
order by len(name),case when type='国际' then 0 else 1 end
-- =========================================
-- -----------t_mac 小编-------------
---希望有天成为大虾----
-- =========================================
IF OBJECT_ID('tb') IS NOT NULL
DROP TABLE tb
GO
CREATE TABLE tb(Id int,Name varchar(10),Type varchar(10) )
go
insert tb SELECT
1 , 'a' , ' 国际' UNION ALL SELECT
2 , 'ae' , '国内' UNION ALL SELECT
3 , 'abc' , '国内' UNION ALL SELECT
4 , 'aec' , '国际'
select *
from tb
order by len(name),case when type='国际' then 0 else 1 end
go
/*--Id Name Type
----------- ---------- ----------
1 a 国际
2 ae 国内
4 aec 国际
3 abc 国内
----------
-------*/
select *
from news
order by len(name),case when type='国际' then 0 else 1 end