我有一张桌子:
ID | 杀戮 | 死亡人数
$ratio = $kills / $deaths;
如何对字段进行排序,以便以最高比率回显 ID?
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
你试过这个:
select id from table order by kills/deaths desc limit 1;
(kills + 0.0)/deaths
如果它没有自动提升为浮动,请尝试。
还要尽量kills/(deaths+0.0001)
防止被零除..
尝试
SELECT TOP 1 ID, cast(Kills/Deaths as float) FROM KillsDeaths
ORDER BY (Kills/Deaths) DESC