3

我有Races行的表IDNameTotalCP。我 SELECT MIN( TotalCP) FROM Races,但是我想选择具有最小值的整行。我怎样才能做到这一点,在一个单一的查询?

4

3 回答 3

11

从聚合值中获取整行的一般形式是:

SELECT *
FROM Races
WHERE TotalCP = (SELECT MIN(TotalCP) FROM Races)

或者

SELECT r.*
FROM
(
    SELECT MIN(TotalCP) t
    FROM Races
) m
INNER JOIN Races r ON m.t = r.TotalCP

但是,在这种情况下,由于您使用的是MIN,您只需排序并取第一行:

SELECT *
FROM Races
ORDER BY TotalCP
LIMIT 1
于 2012-11-08T16:55:26.993 回答
0
Select * from Races
where TotalCP = SELECT MIN( TotalCP ) FROM Races
于 2012-11-08T16:55:27.177 回答
0

子查询是您的选择,

      SELECT * FROM Races where TotalCP = (SELECT MIN( TotalCP ) FROM Races)
于 2012-11-08T16:55:38.223 回答