方法而已,不要死抠代码是否有错:create table myorder(style primary key,顺序号)
select .....
from 查询结果 as a left join myorder as b on a.style=b.style
order by b.顺序号
select .....
from 查询结果 as a left join myorder as b on a.style=b.style
order by b.顺序号
from T
order by (case when style = 200 then 1
when style = 100 then 2
when style = 300 then 3
end)
union
select 2 as aid,* from T where style =100
union
select 3 as aid,* from T where style =300
order by aid
col style
3 100
5 200
9 100
1 300
2 200
8 300
排序后
2 200
5 200
3 100
9 100
1 300
8 300
select col,style from table group by style,col
order by
(case when style = 200 then 1
when style = 100 then 2
when style = 300 then 3
end),col
when style = 100 then 2
when style = 300 then 3
end)
1:
select * from 你的表 order by charindex(','+cast(style as varchar(10))+',',',200,100,300,'),其他字段
2:
select * from 表 order by (case when style = 200 then 1
when style = 100 then 2
when style = 300 then 3
end),其他字段
when style =100 then 2
when style =300 then 3
end),主字段
select * from table where style = 200 order by field1, field2
union
select * from table where style <> 200 order by field1, field22.
select field1, field2, ...fieldn,
GroupId =
CASE style
WHEN 200 THEN 0
ELSE 1
END
order by GroupId, field1, field2如果不认 GroupId ,加上单引号试试。没有SQLSERVER,没有试验。第二种方法主要是注意CASE的使用
select field1, field2, ...fieldn,
GroupId =
CASE
WHEN style=200 THEN 0
WHEN style=100 THEN 1
WHEN style=300 THEN 2
END
order by GroupId, field1, field2orselect field1, field2, ...fieldn,
CASE style
WHEN 200 THEN 0
WHEN 100 THEN 1
WHEN 300 THEN 2
END
order by style, field1, field2没有SQL数据库,都是想当然的,自己试试吧
when style = 100 then 2
when style = 300 then 3
end),主字段
when style = 100 then 2
when style = 300 then 3
end),其他字段