标题几乎是自我解释的。我想找出一种方法来识别一个字段的MAX所在的记录。
答案 0 :(得分:3)
尝试使用MySQL或Postgres:
SELECT * FROM MyTable ORDER BY MyField DESC LIMIT 1
或者使用MSSQL:
SELECT TOP 1 * FROM MyTable ORDER BY MyField DESC
Oracle需要嵌套的SELECT with ROWNUM:
SELECT * FROM (SELECT * FROM MyTable ORDER BY MyField DESC) WHERE ROWNUM = 1
答案 1 :(得分:0)
答案取决于您正在使用的DBMS。 @StileCrisis涵盖了MySQL和MSSQL;在Oracle中,您可以执行以下操作:
SELECT * FROM (
SELECT * FROM mytable ORDER BY myfield DESC
) WHERE rownum = 1;
Postgres使用与MySQL相同的语法:
SELECT * FROM mytable ORDER BY myfield DESC LIMIT 1;