亲爱的SO Cronies,
我尝试使用ORDER BY
或任何可能涉及临时表的以性能为中心的解决方案来自定义带宽数据。我已经搜索了SO和谷歌,并且只发现了我可以使用的部分功能,所以我已经到达这里作为最后一站。
数据(示例)
VALUE
---------
10 Kbps
5 Kbps
1 Mbps
10 Mbps
100 Mbps
10 Gbps
1 Gbps
SQL小提琴,如下所示。你能听到它在后台播放吗?
Bandwidth Sorting Start (SQL Fiddle)
select * from Bandwidth
order by (
case
when Value like '%kbps%' then 1
when Value like '%mbps%' then 2
when Value like '%gbps%' then 3
else 4
end)
我的想法是将字符串Value
拆分为参数并在指标类型上运行案例(例如Kbps,Mbps)然后应用乘数基于该参数并在临时表中显示该参数,我可以对基于int的排序进行排序和返回,而不在结果中显示该列!
提前致谢。我试图在DBA StackExchange上发布,但现有的工作位置目前阻止了那里的登录创建。
答案 0 :(得分:1)
只需使用分隔符分隔数字并将其转换为整数
order by
(
case
when Value like '%Kbps%' then 1
when Value like '%Mbps%' then 2
when Value like '%Gbps%' then 3
else 4
end) ,
CONVERT(INT,SUBSTRING(Value, 0, CHARINDEX(' ', Value)))