0

我正在寻找一个声明来找到一个具有最小值的特殊字段的用户。我的意思是这样的

Select ID, Username, Joindate, MIN(score) 
from table1

实际上,我正在寻找一种方法来找到得分最低的用户。

4

4 回答 4

2

要找到得分最低的用户,您可以简单地对表进行排序并获取第一条记录:

SELECT TOP 1 ID, UserName, JoinDate, score FROM table1 ORDER BY score
于 2013-03-24T18:06:59.087 回答
2

您可以通过几种不同的方式获得此结果。

子查询:

Select t1.ID,
  t1.Username,
  t1.Joindate,
  t1.Score
from table1 t1
inner join
(
  select min(score) LowestScore
  from table1
) t2
  on t1.score = t2.lowestscore

TOP WITH TIES

select top 1 with ties id, username, joindate, score
from table1
order by score

您甚至可以使用排名函数来获得结果:

select id, username, joindate, score
from
(
  select id, username, joindate, score,
    rank() over(order by score) rnk
  from table1
) src
where rnk = 1

请参阅SQL Fiddle with Demo of all queries。

其中每一个都将返回所有得分最低的用户。

于 2013-03-24T18:11:42.350 回答
1

查询可以是 -

Select ID,Username,Joindate,score from table1 
where score in (select MIN(score) from table1)

谢谢

于 2013-03-24T18:10:32.273 回答
0

从 table1 中选择前 1 个 ID、用户名、Joindate、score 其中 score = (select min(score) from table1)

于 2013-03-25T08:37:53.473 回答