0

我有一张桌子:
ID | 杀戮 | 死亡人数
$ratio = $kills / $deaths;

如何对字段进行排序,以便以最高比率回显 ID?

4

3 回答 3

7
WITH CTE AS
(
   SELECT T.*,
       Ratio = kills / deaths, 
       Rank = DENSE_RANK()OVER(PARTITION BY Id ORDER BY kills / deaths DESC) 
   FROM dbo.TableName T
)
SELECT * FROM CTE WHERE Rank = 1
于 2013-05-11T13:45:11.973 回答
2

你试过这个:

select id from table order by kills/deaths desc limit 1;

(kills + 0.0)/deaths如果它没有自动提升为浮动,请尝试。

还要尽量kills/(deaths+0.0001)防止被零除..

于 2013-05-11T13:45:43.343 回答
1

尝试

SELECT TOP 1 ID, cast(Kills/Deaths as float) FROM KillsDeaths
ORDER BY (Kills/Deaths) DESC
于 2013-05-11T13:50:01.137 回答