排序问题求教,多字段排序
根据不同的字段进行排序
例 根据 f1 , f2 ,f3
如果 f1 = 1 则 order by f1,f2,f3
如果 f2 = 2 则 order by f1,f3,f2
如何解决。
我现在的做法是用临时表或者表变量
create table #table1
(
....
id int identity(1,1)
)
insert into #table1(...) values select * from t1 where f1 = 1 order by f2,f3
insert into #table1(...) values select * from t1 where f1 = 2 order by f3,f2
select * from #table1 order by f1,id
请问除此之外还有更好的方案么?上述方法速度必然是很慢的。
by the way
我反复测试用临时表反而比表变量要快一点点。有点不得其解,测试是在查询分析器中进行的。
例 根据 f1 , f2 ,f3
如果 f1 = 1 则 order by f1,f2,f3
如果 f2 = 2 则 order by f1,f3,f2
如何解决。
我现在的做法是用临时表或者表变量
create table #table1
(
....
id int identity(1,1)
)
insert into #table1(...) values select * from t1 where f1 = 1 order by f2,f3
insert into #table1(...) values select * from t1 where f1 = 2 order by f3,f2
select * from #table1 order by f1,id
请问除此之外还有更好的方案么?上述方法速度必然是很慢的。
by the way
我反复测试用临时表反而比表变量要快一点点。有点不得其解,测试是在查询分析器中进行的。
...全文
相关推荐
C# List OrderBy 动态多字段排序
C# 使用orderby 多字段 动态排序
SQL-ORDER BY 多字段排序(升序、降序)
本节主要介绍了SQL-ORDER BY 多字段排序包括升序、降序,下面有个示例,大家可以参考下
C# IList多字段排序
对实现IList接口的类进行排序,支持多字段排序。
MySQL中按照多字段排序及问题解决
主要介绍了MySQL中按照多字段排序及问题解决的方法,非常的实用,有需要的小伙伴可以参考下。
MySQL中Order By多字段排序规则代码示例
主要介绍了MySQL中Order By多字段排序规则代码示例,小编觉得挺不错的,这里给大家分享下,需要的朋友可以参考。


应用实例

