TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

SQL: Select only rows with Max Value on a Column

6 点作者 adrianonantua超过 11 年前

2 条评论

baxter001超过 11 年前
Or those who happen to be using a dialect of sql with window functions, selecting the rows where:<p>ROW_NUMBER() OVER(PARTITION BY Id ORDER BY Rev DESC) AS &quot;Row Number&quot;<p>Returns 1 is clearer to my mind, with some caveats around dialects which use separate forms of row-number that assign identical&#x2F;differing numbers to two consecutive identical rows.
goldenkey超过 11 年前
I prefer SELECT table.* FROM table WHERE rev = (SELECT MAX(rev) FROM table WHERE id=table.id)<p>I hate joins. Subselects are so much clearer imo - and you don&#x27;t end up with extra fields.