首页 > 解决方案 > 带有 SELECT 语句的尾随“000000000000003”

问题描述

我在数据库中有以下架构和数据:

Create table Scores (Id int, Score NUMBER(3,2))
Truncate table Scores
insert into Scores (Id, Score) values ('1', '3.5')
insert into Scores (Id, Score) values ('2', '3.65')
insert into Scores (Id, Score) values ('3', '4.0')
insert into Scores (Id, Score) values ('4', '3.85')
insert into Scores (Id, Score) values ('5', '4.0')
insert into Scores (Id, Score) values ('6', '3.65')

我写了以下查询:

SELECT Score, DENSE_RANK() OVER (ORDER BY Score DESC) AS Rank FROM Scores;

它适用于大多数结果。Scores但有时我会在结尾0和结尾得到值3,例如:57.43000000000000003.

有人可以解释为什么会这样吗?

更新:

解决这个问题: https ://leetcode.com/problems/rank-scores/

添加ROUND(Score, 2),它工作正常。但仍然不清楚尾随零。

标签: sqloracle

解决方案


推荐阅读