根据sql server中另一列的最小值返回一个值

时间:2022-08-22 13:50:17

I am looking to do this:

我希望这样做:

SELECT [Name] FROM MyTable WHERE IsAlive = 1 AND MIN(ID)

I am looking to get [Name] for a person in MyTable that has the lowest ID number and I think I am going crazy.

我希望得到[姓名]为MyTable中具有最低身份证号码的人,我想我会发疯。

1 个解决方案

#1


3  

The MIN aggregate function is not going to return a boolean value. It's going to return the MIN of that field in that result set. Just order it properly and grab the TOP 1.

MIN聚合函数不会返回布尔值。它将返回该结果集中该字段的MIN。只需正确订购并抓住TOP 1。

SELECT TOP 1 [Name] FROM MyTable WHERE IsAlive = 1 ORDER BY ID

#1


3  

The MIN aggregate function is not going to return a boolean value. It's going to return the MIN of that field in that result set. Just order it properly and grab the TOP 1.

MIN聚合函数不会返回布尔值。它将返回该结果集中该字段的MIN。只需正确订购并抓住TOP 1。

SELECT TOP 1 [Name] FROM MyTable WHERE IsAlive = 1 ORDER BY ID