SQL如何按两数相除后的结果由大到小进行排序。谢谢。
数据库中有一个表。表(tb)中有如下字段 id,t1,t2
现要得出如下结果。按 t1/t2 (t1除于t2) 的值由大到小进行排序,取出前面十条记录
------解决方案--------------------select top 10 * from t order by cast(t1 as float)/t2
------解决方案--------------------select top 10 * from tb order by t1/t2
如果t1,t2类型不对,可能要做类型转换
------解决方案----------------------t2不能为0
select top 10 * from t order by case when t2> 0 then round(t1/t2,2) end
------解决方案--------------------SELECT TOP 10 *
FROM table1
WHERE t2 <> 0
ORDER BY (t1+0.00)/t2 DESC