Select MIN 十进制值

Select MIN decimal value

我有一个场景,我在文件中有重复数据 - 'unique' 标识符相同。

我正在尝试确定 'Outcome1' 字段中的哪个十进制值是 MIN 值,然后会给出不重复的结果。

我尝试使用 MIN,但它似乎不起作用,因为我必须按 'Outcome1' 字段分组。

当前的 table 看起来像这样:

ID Outcome1 Outcome2
1 186.5098 133.8825
1 186.5093 133.8820

预期结果如下:

ID Outcome1 Outcome2
1 186.5093 133.8820

非常感谢任何帮助。

假设您想要 Outcome1 和 Outcome2 中的最低值,您可以使用基本 MIN 来执行此操作。

select ID
    , Outcome1 = MIN(Outcome1)
    , Outcome2 = MIN(Outcome2)
from YourTable
group by ID

如果您只想考虑结果 1,可以使用 row_number

with outcome as (
    select *,
        Row_Number() over(partition by id order by Outcome1 ) rn
    from t
)
select Id, Outcome1, Outcome2
from outcome
where rn=1

在部分查询中使用 Row_number(),然后获取带有数字 1

的行
select * from (
   SELECT 
   [id]
  ,[Outcome1]
  ,[Outcome2]
  , ROW_NUMBER() over( partition by id order by Outcome1) As RowN
  FROM [Test].[dbo].[Table_4]
 ) tt
 where tt.RowN=1